-
methodname(path, options={}, success=null, error=null)
-
path
is the url endpoint to make the request. For ex: first set the base url using setBaseURL(base)
and then you can call Fetch.get('/user/1')
-
options
: you have to pass options
object for each function call even if its value is empty({}
).
-
In options
you can pass values like:
data
:
- If the called method is
get
, the key-value pair in data
will be appended to the called url as a querystring. - Otherwise it will be posted as JSON body unless
options.form
is true
. In that case, the data will be posted as multipart/form-data
.
form
- If this value is true,
data
will be posted as Form
, otherwise as JSON
. Use form: true
if you are uploading files.
headers
- Pass additional headers as an object.
-
success
is a function that is passed the success response of a Fetch
call like success(data)
.
-
error
is a function that is passed the error response of a Fetch
call like error(err)
. Here, err
has code
that is the http error code and response
that is the error data that was sent by the server.
-
You can also call Fetch.clear(prefix)
to manually clear the cache. All cached urls starting with prefix
will be cleared.
-
If you call Fetch.clear()
without any arguments, the full cache will be cleared.