<div align="center">
<img src="logo.png" alt="httpie" height="190" />
</div>
<div align="center">
<a href="https://npmjs.org/package/httpie">
<img src="https://badgen.now.sh/npm/v/httpie" alt="version" />
</a>
<a href="https://travis-ci.org/lukeed/httpie">
<img src="https://badgen.now.sh/travis/lukeed/httpie" alt="travis" />
</a>
<a href="https://codecov.io/gh/lukeed/httpie">
<img src="https://badgen.now.sh/codecov/c/github/lukeed/httpie" alt="codecov" />
</a>
<a href="https://npmjs.org/package/httpie">
<img src="https://badgen.now.sh/npm/dm/httpie" alt="downloads" />
</a>
</div>
<div align="center">A Node.js HTTP client as easy as pie!</div>
## Features
* `Promise`- based HTTP requestor
* Works with HTTP and HTTPS protocols
* Automatically handles JSON requests and responses
* Extremely lightweight with **no dependencies** 678 bytes!
* Includes aliases for common HTTP verbs: `get`, `post`, `put`, `patch`, and `del`
Additionally, this module is delivered as:
* **ES Module**: [`dist/httpie.mjs`](https://unpkg.com/httpie/dist/httpie.mjs)
* **CommonJS**: [`dist/httpie.js`](https://unpkg.com/httpie/dist/httpie.js)
## Install
```
$ npm install --save httpie
```
## Usage
> **Note:** The `async` syntax is for demo purposes – you may use Promises in a Node 6.x environment too!
```js
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);
}
```
## API
### send(method, url, opts={})
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](#error-handling). Otherwise, the Promise will resolve with the full [`ClientRequest`](https://nodejs.org/api/http.html#http_class_http_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!
#### method
Type: `String`
The HTTP method name – it must be uppercase!
#### url
Type: `String` or [`URL`](https://nodejs.org/api/url.html#url_the_whatwg_url_api)
If `url` is a string, it is automatically parsed with [`url.parse()`](https://nodejs.org/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost) into an object.
#### opts.body
Type: `Mixed`<br>
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`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type) header will be attached.
Additionally, `httpie` will _always_ set a value for the [`Content-Length`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Length) header!
#### opts.headers
Type: `Object`<br>
Default: `{}`
The custom headers to send with your request.
#### opts.redirect
Type: `Boolean`<br>
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`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location) header.
#### opts.reviver
Type: `Function`<br>
Default: `undefined`
An optional function that's passed directly to [`JSON.parse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Parameters), 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!
### get(url, opts={})
> Alias for [`send('GET', url, opts)`](#sendmethod-url-opts).
### post(url, opts={})
> Alias for [`send('POST', url, opts)`](#sendmethod-url-opts).
### put(url, opts={})
> Alias for [`send('PUT', url, opts)`](#sendmethod-url-opts).
### patch(url, opts={})
> Alias for [`send('PATCH', url, opts)`](#sendmethod-url-opts).
### del(url, opts={})
> Alias for [`send('DELETE', url, opts)`](#sendmethod-url-opts).
## Error Handling
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;
> **Important:** The error's `data` property may also be parsed to a JSON object, according to the response's headers.
```js
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>
```
## License
MIT © [Luke Edwards](https://lukeed.com)
没有合适的资源?快使用搜索试试~ 我知道了~
docker:用于Unity的一系列CI专用docker映像。 取代著名的gablerouxunity3d图像
共376个文件
meta:149个
tif:45个
asset:44个
需积分: 50 1 下载量 184 浏览量
2021-02-06
07:15:39
上传
评论
收藏 14.17MB ZIP 举报
温馨提示
适用于Unity的Docker映像 (不隶属于Unity Technologies) CI适用于Unity的CI专业Docker映像的来源,可供所有人免费使用。 请找到我们的以获取任何相关。 基础 有关基本映像的用法,请参见。 枢纽 有关集线器映像的用法,请参见。 编辑 有关器映像的用法,请参见。 社区 随时加入我们 并与社区互动。 贡献 要做出贡献,请在同意我们并阅读后,查看。 执照
资源详情
资源评论
资源推荐
收起资源包目录
docker:用于Unity的一系列CI专用docker映像。 取代著名的gablerouxunity3d图像 (376个子文件)
Rotation.anim 4KB
EditorTests.asmdef 348B
Tests.asmdef 320B
ProjectSettings.asset 19KB
ProjectSettings_il2cpp.asset 17KB
ProjectSettings.asset 17KB
InputManager.asset 10KB
QualitySettings.asset 6KB
InputManager.asset 6KB
QualitySettings.asset 4KB
SampleSceneProfile.asset 3KB
GraphicsSettings.asset 3KB
Readme.asset 3KB
GraphicsSettings.asset 2KB
Physics2DSettings.asset 2KB
Physics2DSettings.asset 2KB
UniversalRP-MediumQuality.asset 2KB
UniversalRP-HighQuality.asset 2KB
UniversalRP-LowQuality.asset 2KB
NavMeshAreas.asset 1KB
ForwardRenderer.asset 1KB
NavMeshAreas.asset 1KB
DynamicsManager.asset 1KB
DynamicsManager.asset 1KB
EditorSettings.asset 1KB
PackageManagerSettings.asset 1003B
UnityConnectSettings.asset 853B
UnityConnectSettings.asset 853B
PresetManager.asset 824B
EditorSettings.asset 718B
AudioManager.asset 432B
TagManager.asset 421B
EditorUserSettings.asset 420B
AudioManager.asset 413B
URPProjectSettings.asset 410B
TagManager.asset 378B
VFXManager.asset 284B
VFXManager.asset 273B
EditorBuildSettings.asset 268B
EditorBuildSettings.asset 257B
TimeManager.asset 204B
TimeManager.asset 202B
VersionControlSettings.asset 196B
XRSettings.asset 167B
ClusterInputManager.asset 120B
PresetManager.asset 120B
ClusterInputManager.asset 114B
asound.conf 52B
SimpleCameraController.cs 6KB
ReadmeEditor.cs 4KB
EditorTests.cs 698B
Tests.cs 692B
Readme.cs 272B
Assembly-CSharp.csproj 43KB
Dockerfile 5KB
Dockerfile 1KB
Dockerfile 1KB
.dockerignore 58B
.editorconfig 172B
paintbucket_low.fbx 131B
ConstructionLight_Low.fbx 131B
jigsaw_low.fbx 131B
Workbench.fbx 131B
Workbench_Low.fbx 131B
Workshop_Set.fbx 131B
hammer_low.fbx 130B
small_plane.fbx 130B
Stud.fbx 130B
magneticlevel_low.fbx 130B
safetyhat_low.fbx 130B
brush_low.fbx 130B
safetygoggles_low.fbx 130B
.gitattributes 2KB
.gitignore 512B
.gitignore 182B
.gitignore 22B
core.js 8KB
index.js 4KB
command.js 2KB
httpie.js 2KB
httpie.esm.js 1KB
file-command.js 1KB
httpie.min.js 1KB
utils.js 620B
packages-lock.json 9KB
manifest.json 2KB
package.json 912B
package.json 777B
package.json 298B
license 1KB
LICENSE 1KB
SampleSceneLightingSettings.lighting 2KB
yarn.lock 601B
core.js.map 4KB
command.js.map 2KB
file-command.js.map 646B
utils.js.map 393B
Jigsaw_Mat.mat 3KB
Plastic_Ridges_Mat.mat 3KB
Stud_Mat.mat 3KB
共 376 条
- 1
- 2
- 3
- 4
鑨鑨
- 粉丝: 26
- 资源: 4654
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0