-
-
Notifications
You must be signed in to change notification settings - Fork 5
Simple API
StefansArya edited this page Apr 7, 2021
·
2 revisions
This feature give you simple interface for using sf.request
for accessing API with your server.
// The first parameter are required to be filled with your API URL.
// You don't need the last slash "/"
var myAPI = new sf.API('http://example.com/api');
After you added the access token, X-Authorization: Bearer {token here}
header will be added on every HTTP request.
myAPI.accessToken = "{token here}";
This feature will wrap your HTTP method inside _method
on the request data and send HTTP request with POST
method.
To turn off this behavior you set myAPI.mask
to false.
data and beforeSend parameter are optional
myAPI.request(method, url, data, beforeSend);
// Example URL-> http://example.com/api/add-user
myAPI.request('POST', '/add-user', {name:"Alex"})
.done(function(data, statusCode){
// The response data will automatically being parsed from JSON to Object
console.log("Got user ID:", data.id);
});
myAPI.request
will return XMLHttpRequest, you can also use await
just like using sf.request
.
data parameter are optional
myAPI.get(url, data);
myAPI.post(url, data);
myAPI.delete(url, data);
myAPI.put(url, data);
- Framework
-
Installation
- Build Configuration
- Hot Reload
- Loader
- Model
-
Component
- Reserved Element
- Empty Shell
- Include external template
- Space
-
Views (Router)
- URI
- Static Template
- Language
- Element's query helper
- Events
- URL Request
- Window Extends