Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Promise
- based HTTP requestorget
, post
, put
, patch
, and del
Additionally, this module is delivered as:
dist/httpie.mjs
dist/httpie.js
$ npm install --save httpie
Note: The
async
syntax is for demo purposes – you may use Promises in a Node 6.x environment too!
import { get, post } from 'httpie';
try {
const { data } = await get('https://pokeapi.co/api/v2/pokemon/1');
// Demo: Endpoint will echo what we've sent
const res = await post('https://jsonplaceholder.typicode.com/posts', {
body: {
id: data.id,
name: data.name,
number: data.order,
moves: data.moves.slice(0, 6)
}
});
console.log(res.statusCode); //=> 201
console.log(res.data); //=> { id: 1, name: 'bulbasaur', number: 1, moves: [{...}, {...}] }
} catch (err) {
console.error('Error!', err.statusCode, err.message);
console.error('~> headers:', err.headers);
console.error('~> data:', err.data);
}
Returns: Promise
Any httpie.send
request (and its aliases) will always return a Promise.
If the response's statusCode
is 400 or above, this Promise will reject with a formatted error – see Error Handling. Otherwise, the Promise will resolve with the full ClientRequest
stream.
The resolved response will receive a new data
key, which will contain the response's full payload. Should the response return JSON content, then httpie
will parse it and the res.data
value will be the resulting JSON object!
Type: String
The HTTP method name – it must be uppercase!
Type: String
or URL
If url
is a string, it is automatically parsed with url.parse()
into an object.
Type: Mixed
Default: undefined
The request's body, can be of any type!
Any non-Buffer
objects will be converted into a JSON string and the appropriate Content-Type
header will be attached.
Additionally, httpie
will always set a value for the Content-Length
header!
Type: Object
Default: {}
The custom headers to send with your request.
Type: Boolean
Default: true
Whether or not redirect responses should be followed automatically.
Note: This may only happen with a 3xx status and if the response had a
Location
header.
Type: Function
Default: undefined
An optional function that's passed directly to JSON.parse
, allowing you transform aspects of the response data before the httpie
request resolves.
Note: This will only run if
httpie
detects that JSON is contained in the response!
Type: Integer
Default: undefined
The time, in milliseconds, before automatically terminating the request.
When the request exceeds this limit, httpie
rejects with an err<Error>
, adding a truthy err.timeout
value.
Important: There is a slight behavioral difference between the Node & browser versions!
In the server, thetimeout
value does not propagate to any redirects.
In the browser, thetimeout
value will not reset during redirects.
Type: Boolean
Default: false
Whether or not cross-site requests should include credentials (such as cookies).
This value is passed directly to XMLHttpRequest.withCredentials
.
Important: This is for the browser version only!
Alias for
send('GET', url, opts)
.
Alias for
send('POST', url, opts)
.
Alias for
send('PUT', url, opts)
.
Alias for
send('PATCH', url, opts)
.
Alias for
send('DELETE', url, opts)
.
All responses with statusCode >= 400
will result in a rejected httpie
request. When this occurs, an Error instance is formatted with complete information:
err.message
– String
– Identical to err.statusMessage
;err.statusMessage
– String
– The response's statusMessage
value;err.statusCode
– Number
– The response's statusCode
value;err.headers
– Object
– The response's headers
object;err.data
– Mixed
– The response's payload;Additionally, errors that are a result of a timeout expiration will have a truthy err.timeout
value.
Important: The error's
data
property may also be parsed to a JSON object, according to the response's headers.
import { get } from 'httpie';
get('https://example.com/404').catch(err => {
console.error(`(${err.statusCode}) ${err.message}`)
console.error(err.headers['content-type']);
console.error(`~> ${err.data}`);
});
//=> "(404) Not Found"
//=> "text/html; charset=UTF-8"
//=> ~> <?xml version="1.0" encoding="iso-8859-1"?>\n<!DOCTYPE html ...</body>\n</html>
MIT © Luke Edwards
FAQs
A lightweight, Promise-based wrapper for Node.js HTTP requests~!
The npm package httpie receives a total of 9,655 weekly downloads. As such, httpie popularity was classified as popular.
We found that httpie demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.