Installations
npm install okhttp
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
*
Node Version
6.2.0
NPM Version
3.8.9
Score
75
Supply Chain
99.5
Quality
75.3
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
HendrixString
Download Statistics
Total Downloads
11,888
Last Day
8
Last Week
43
Last Month
125
Last Year
880
GitHub Statistics
11 Stars
31 Commits
2 Watching
1 Branches
1 Contributors
Bundle Size
14.46 kB
Minified
3.43 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.1.0
Package Id
okhttp@1.1.0
Size
56.08 kB
NPM Version
3.8.9
Node Version
6.2.0
Total Downloads
Cumulative downloads
Total Downloads
11,888
Last day
300%
8
Compared to previous day
Last week
104.8%
43
Compared to previous week
Last month
42%
125
Compared to previous month
Last year
-62.2%
880
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
3
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
1const okhttp = require('okhttp'); 2 3var MimeBuilder = okhttp.MimeBuilder; 4var Request = okhttp.Request; 5var RequestBody = okhttp.RequestBody; 6var RequestBuilder = okhttp.RequestBuilder; 7var FormEncodingBuilder = okhttp.FormEncodingBuilder; 8var MultiPartBuilder = okhttp.MultiPartBuilder; 9 10/** 11 * @param msg a {data, response, request} Object 12 */ 13private function onComplete(msg):void { 14 console.log('data ' + msg.data + ', response ' + msg.response.statusCode + ', request ' + msg.request.method); 15} 16 17private function onError(err):void { 18 console.error(err); 19} 20
1) Simple textual GET
request
1new RequestBuilder().GET('http://google.com').buildAndExecute().then(onComplete).catch(onError); 2
2) Simple binary GET
request
- data returns as a buffer
1new RequestBuilder().GET('http://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png').bufferResponse().buildAndExecute().then(onComplete).catch(onError); 2
2) Simple JSON POST
request
1new RequestBuilder().url('http://httpbin.org/post') 2 .POST(RequestBody.create({a:'a1', b:'b1'}, new MimeBuilder().contentType('application/json', 'charset', 'utf8').build())) 3 .buildAndExecute().then(onComplete).catch(onError); 4
3) Form Encoding POST (www-form-urlencoded)
request
1let fe_body = new FormEncodingBuilder().add('key1', 'value1').add('key2', 'value2').build(); 2 3new RequestBuilder().url('http://httpbin.org/post').POST(fe_body).buildAndExecute() 4 .then(onComplete).catch(onError); 5
4) MultiPart
request:
- send a multipart file upload request to Google Drive API
- to obtain token, use https://developers.google.com/oauthplayground/
1let json = JSON.stringify({title:'test'}); 2var image = fs.readFileSync(path.resolve(__dirname, 'test.jpg')); 3 4let mp_body = new MultiPartBuilder().addPart(RequestBody.create(json, 'Content-Type: application/json; charset=UTF-8')) 5 .addPart(RequestBody.create(image, new MimeBuilder().contentType('image/jpeg').contentTransferEncoding('binary').build())) 6 .type(MultiPartBuilder.FORMDATA).build(); 7 8new RequestBuilder().url('https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart') 9 .header('Authorization', 'Bearer OAUTH2_TOKEN_HERE') 10 .POST(mp_body).buildAndExecute().then(onComplete).catch(onError); 11
5) POST
image request
- send an image into
Google Glass Mirror API
1public function uploadImage(image, itemId, oauthToken):void { 2 3 var body = RequestBody.create(image, 'Content-Type: image/png'); 4 5 new RequestBuilder().url("https://www.googleapis.com/upload/mirror/v1/timeline" + "/" + itemId + "/attachments") 6 .query("access_token", oauthToken) 7 .POST(body).build().execute() 8 .then(onComplete).catch(onError); 9} 10
Dev Dependencies
Terms
- completely free source code. Apache License, Version 2.0.
- if you like it -> star or share it with others
Contact Author
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to okhttp
cordova-plugin-okhttp
Uses OkHttp for network requests initiated from Java (e.g. via FileTransfer plugin).
nativescript-okhttp
[OkHttp](http://square.github.io/okhttp/) is an HTTP client that supports:
prhttp
A JavaScript HTTP interceptor inspired by okhttp
@goast/kotlin
Provides gOAst generators for generating Kotlin code from OpenAPI specifications.