From c737ad9482e29e728299f229237f4a25740a9e55 Mon Sep 17 00:00:00 2001 From: David Frank Date: Wed, 28 Jan 2015 02:02:27 +0800 Subject: [PATCH] doc update --- CHANGELOG.md | 8 ++++++++ LIMITS.md | 4 +++- README.md | 31 +++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 142b0f5..4301f51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ Changelog ========= + +# 1.x release + +## v1.0.0 + +- Enhance: better test coverage and doc + + # 0.x release ## v0.1 diff --git a/LIMITS.md b/LIMITS.md index 8eb6307..0e289e9 100644 --- a/LIMITS.md +++ b/LIMITS.md @@ -2,7 +2,7 @@ Known limits ============ -*As of 0.x release* +*As of 1.x release* - Topics such as cross-origin, content security policy, mixed content, service workers are ignored, given our server-side context. @@ -14,4 +14,6 @@ Known limits - Similarly, `req.body` can either be a string or a readable stream. +- Only support `res.text()` and `res.json()` at the moment, until there are good use-cases for blob. + - There is currently no built-in caching, as server-side caching varies by use-cases. diff --git a/README.md b/README.md index 3dc9aa1..888709a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ Hence `node-fetch`, minimal code for a `window.fetch` compatible API on node.js - Stay consistent with `window.fetch` API. - Make conscious trade-off when following [whatwg fetch spec](https://fetch.spec.whatwg.org/) and [stream spec](https://streams.spec.whatwg.org/) implementation details, document known difference. - Use native promise, but allow substituting it with [insert your favorite promise library]. +- Use native stream for body, on both request and response. +- Decode content encoding (gzip/deflate) properly, and convert string output (such as `res.text()` and `res.json()`) to utf-8 automatically. +- Useful extensions such as timeout, redirect limit, response size limit. # Difference from client-side fetch @@ -120,6 +123,34 @@ co(function *() { See [test cases](https://github.com/bitinn/node-fetch/blob/master/test/test.js) for more examples. +# API + +## fetch(url, options) + +Returns a `Promise` + +### Url + +Should be an absolute url, eg `http://example.com/` + +### Options + +default values are shown, note that only `method`, `headers` and `body` are allowed in `window.fetch`, others are node.js extensions. + +``` +{ + method: 'GET' + , headers: {} // request header, format {a:1} or {b:[1,2,3]} + , follow: 20 // maximum redirect count, 0 to disable + , timeout: 0 // request timeout in ms, 0 to disable, note that it's for each request when following redirect + , compress: true // support gzip/deflate content encoding, false to disable + , size: 0 // maximum response body size in bytes, 0 to disable + , body: empty // request body, can be a string or readable stream + , agent: null // custom http.Agent instance +} +``` + + # License MIT