Properties:
Name | Type | Description |
---|---|---|
env |
String | the Javascript run-time, it should be 'dev' or 'prod' |
Example
ajah
.openInterceptor(function (method, url, isAsync) {
method = method === 'DELETE' ? 'GET' : method; // change the http method
return [method, url, isAsync];
})
.itShouldOpen(function (method, url, isAsync) {
if (method === 'DELETE') return false; // if the method is DELETE, the it will not hand shake with the serve
return true;
})
.itShouldSend(function (method, url, body, headers) {
if (!headers.Authorization) return false; // if this request without token field, so don't send thi request
return true;
})
.transformHeaders(function (method, url, body, headers) {
headers['Authorization'] = 'this is a mock token'; // add a headers field for this request
return headers;
})
.transformRequestBody(function (method, url, body, headers) {
if (method === 'GET') return null; // if method is GET, then it should not send any body.
return body;
})
.transformResponseBody(function (method, url, body, headers, response) {
// TODO
return response;
})
.itShouldAbort(function (method, url, body, headers) {
if (url.indexOf('https://') < 0) return true; // if this request is not https, then abort this request.
return false;
});
Methods
(static) itShouldAbort(callback) → {ajah}
after the request was sent, this request should abort or not.
after the request was sent, this request should abort or not
Parameters:
Name | Type | Description |
---|---|---|
callback |
itShouldCallback |
Returns:
- Type
- ajah
(static) itShouldOpen(callback) → {ajah}
it should be hand-shake with serve or not.
it should be hand-shake with serve or not
Parameters:
Name | Type | Description |
---|---|---|
callback |
itShouldOpenCallback |
Returns:
- Type
- ajah
(static) itShouldSend(callback) → {ajah}
this request should be send or not.
this request should be send or not
Parameters:
Name | Type | Description |
---|---|---|
callback |
itShouldCallback |
Returns:
- Type
- ajah
(static) openInterceptor(callback) → {ajah}
hook before call .open() method, and you can change the arguments.
hook before call .open() method, and you can change the arguments
Parameters:
Name | Type | Description |
---|---|---|
callback |
openInterceptorCallback |
Returns:
- Type
- ajah
(static) transformHeaders(callback) → {ajah}
transform the request headers.
transform the request headers
Parameters:
Name | Type | Description |
---|---|---|
callback |
headerTransformCallback |
Returns:
- Type
- ajah
(static) transformRequestBody(callback) → {ajah}
transform the request body.
transform the request body
Parameters:
Name | Type | Description |
---|---|---|
callback |
bodyTransformCallback |
Returns:
- Type
- ajah
(static) transformResponseBody(callback) → {ajah}
transform the response body.
transform the response body
Parameters:
Name | Type | Description |
---|---|---|
callback |
bodyTransformCallback |
Returns:
- Type
- ajah