The HTTP service allows you to create HTTP calls and receive Javascript promises to manage your call response results.
All of Litespeed.js internal HTTP calls used by the framework are managed by the HTTP service.
Currently the HTTP service uses the XMLHttpRequest API to handle all HTTP calls but in future releases we do intend to start using the newer Fetch API.
- get(url)
- post(url, headers, payload)
- put(url, headers, payload)
- patch(url, headers, payload)
- delete(url)
- addGlobalParam(key, value)
- addGlobalHeader(key, value)
Make and HTTP GET request
Param | Type | Description |
---|---|---|
url | string | HTTP URL to the resource you want to request |
This method returns a Javascript Promise object.
http.get('https://example.com')
.then(function (response) {
// Handle Success
}, function (error) {
// Handle Error
}
);
Make and HTTP POST request
Param | Type | Description |
---|---|---|
url | string | HTTP URL to the resource you want to request |
headers | object | HTTP headers object combined from key and values |
payload | string | HTTP payload |
This method returns a Javascript Promise object.
http.post('https://example.com/resource', {'Content-type': 'application/json'}, '{name: "John", age: 31, city: "New York"}')
.then(function (response) {
// Handle Success
}, function (error) {
// Handle Error
}
);
Make and HTTP PUT request
Param | Type | Description |
---|---|---|
url | string | HTTP URL to the resource you want to request |
headers | object | HTTP headers object combined from key and values |
payload | string | HTTP payload |
This method returns a Javascript Promise object.
http.put('https://example.com/resource', {'Content-type': 'application/json'}, '{name: "John", age: 31, city: "New York"}')
.then(function (response) {
// Handle Success
}, function (error) {
// Handle Error
}
);
Make and HTTP PATCH request
Param | Type | Description |
---|---|---|
url | string | HTTP URL to the resource you want to request |
headers | object | HTTP headers object combined from key and values |
payload | string | HTTP payload |
This method returns a Javascript Promise object.
http.patch('https://example.com/resource', {'Content-type': 'application/json'}, '{name: "John", age: 31, city: "New York"}')
.then(function (response) {
// Handle Success
}, function (error) {
// Handle Error
}
);
Make and HTTP DELETE request
Param | Type | Description |
---|---|---|
url | string | HTTP URL to the resource you want to request |
This method returns a Javascript Promise object.
http.delete('https://example.com/resource')
.then(function (response) {
// Handle Success
}, function (error) {
// Handle Error
}
);
Add a global query param to all your HTTP requests. The parameter you will be adding using this method will be attached to any HTTP request sent using the HTTP service.
Param | Type | Description |
---|---|---|
key | string | Parameter name |
value | string | Parameter value |
Items New elements of the Array.
http.addGlobalParam('version', 'beta');
Add a global header to all your HTTP requests. The HEADER you will be adding using this method will be attached to any HTTP request sent using the HTTP service.
Param | Type | Description |
---|---|---|
key | string | Header name |
value | string | Header value |
Items New elements of the Array.
http.addGlobalHeader('Content-type', 'application/json');