node-OkHttP
a lightweight HTTP
library for Node.js
inspired by Square's Android OkHttp
Builder patterns and flavours
for constructing a legit HTTP
requests of all types.
Written entirely in EcmaScript 6 (Harmony) and transpiled with Babel
.
How to use
npm install okhttp
npm install --production okhttp
(if you have the following modules installed globallybabel-cli, babel-plugin-transform-object-assign,babel-preset-es2015
, then use)
Features
- supports all
HTTP
methods. - supports MultiPart requests.
- includes Builders for:
Request
builder.Form Encoding
body builder.Multipart
body builder.Mime
builder.Request Body
composer.
- use
Promise
api for intuitive async. - most important: quick and easy to use.
Guide
const okhttp = ; var MimeBuilder = okhttpMimeBuilder;var Request = okhttpRequest;var RequestBody = okhttpRequestBody;var RequestBuilder = okhttpRequestBuilder;var FormEncodingBuilder = okhttpFormEncodingBuilder;var MultiPartBuilder = okhttpMultiPartBuilder; /** * @param msg a {data, response, request} Object */private :void { console;} private :void { console;}
GET
request
1) Simple textual ;
GET
request
2) Simple binary - data returns as a buffer
;
JSON POST
request
2) Simple ;
Form Encoding POST (www-form-urlencoded)
request
3) let fe_body = ; ;
MultiPart
request:
4) - send a multipart file upload request to Google Drive API
- to obtain token, use https://developers.google.com/oauthplayground/
let json = JSON;var image = fs; let mp_body = typeMultiPartBuilderFORMDATA; ;
POST
image request
5) - send an image into
Google Glass Mirror API
public :void { var body = RequestBody; ;}
Dev Dependencies
Terms
- completely free source code. Apache License, Version 2.0.
- if you like it -> star or share it with others