# stream
A series of stream api. It provides a network request.
# API
# fetch
Start a network request, use two callbacks to receive server's response data.
# fetch(options, callback, progressCallback)
- @options, the request options, key value style dictionary.
method, string, the HTTP methodGETorPOST.url, string, the request url.headers, object, the HTTP request headers.type, string, response type, 'json','text' or 'jsonp'(same as 'json' in native implementation)body, string, the HTTP body.
WARNING
- The
bodyparameter only supports arguments of typestring. Do not use theJSONformat directly, you must convert it to a string. - The
GETrequest does not support arguments asbody. Please use the URL to set the parameters. - The default value of
Content-Typeisapplication/x-www-form-urlencoded. - If you need to send data in
JSONformat via POST, you need to setContent-Typetoapplication/json.
@callback, a callback function whose argument is the response object of the request. Callback function will receive a
responseobject.status, number, response status code.ok, boolean, true if status code is bewteen 200~299.statusText, string, status textdata, string, response data. It's a object if request option isjson/jsonp, or (string) in other type value.headers, object, response headers.
@progressCallback, function, a progress callback. This callback will be invoked before request finished.
readyState, number, current request state.'1':request connection opened;'2':response headers received.;'3':response data is loading;status, number, response status code.lengthnumber, bytes of data have received. You can read full length of response from 'headers'.statusText, string, status text.headers. object, response headers.
TIP
- Default Content-Type is 'application/x-www-form-urlencoded'. (The type specified in fetch is the response type!)
- You need to set the Content-Type header to 'application/json' manually if you want to post the json body.
Demos