gofer-js
go·fer - noun (/ˈɡōfər/) a person who runs errands
Gofer is a JavaScript powerful AJAX tool set for creating and executing
go
Configuration
go;
Property | Type | Description |
---|---|---|
timeout | number |
the number of milliseconds to wait for a response |
urlPrefix | string |
the path prefix. Use to append all requests with a common root path |
onerror | function |
global function to call when an error occurs in a request |
onprogress | function |
global function to call when a request is executing (called on start and end) |
Options
go
Proxies
Gopher includes the ability to create proxies (much like RESTEasy)
let customerProxy = go;
// call the proxy method customerProxy; // you can also call the method with just arguments// they will be added sequentially, as specified in the path customerProxy;
Data Mappers
Data mappers provide serializers and deserializers for AJAX data. Mappers comprise of two
methods: serialize
and deserialize
. Included are mappers for JSON, plain text, and XML.
let MyJSONMapper = { serialize: function(data) { return JSON.stringify(data); }, deserialize: function(data) { return (data) ? JSON.parse(data) : null; }}; // add the mapper to the registry go.mappers.add('json', MyJSONMapper, [ 'application/json', 'text/json' ]);
Handling the Result
go;
Methods
go.get(url, options)
Performs a GET request on the specified URL
string
url, Object|string|number
data, ?Object
options)
go.post(Performs a POST request
go.put(url, data, options)
Performs a PUT request
go.del(url, options)
Performs a DELETE request
go.head(url, options)
Performs a HEAD request
go.fetch(url)
Fetches a resource relative to the current location