Skip to content

Commit b680eaf

Browse files
committed
Merge pull request #52 from yahoo/api
[skip-ci] Update README with API section
2 parents f42ad99 + d3f01d7 commit b680eaf

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,75 @@ new Fetcher({
170170

171171
This `_csrf` will be sent in all XHR requests as a query parameter so that it can be validated on the server.
172172

173+
[//]: # (API_START)
174+
## Fetchr API
175+
176+
### Constructor(options)
177+
178+
Creates a new fetchr plugin instance with the following parameters:
179+
180+
* `options`: An object containing the plugin settings
181+
* `options.req` (required): The request object. It can contain per-request/context data.
182+
* `options.xhrPath` (optional): The path for XHR requests. Will be ignored serverside.
183+
184+
### Static Methods
185+
186+
#### registerFetcher(service)
187+
188+
register a service with fetchr
189+
190+
```js
191+
var Fetcher = require('fetchr');
192+
193+
Fetcher.registerFetcher(myDataService);
194+
```
195+
196+
#### getFetcher(resource)
197+
198+
getter for a service by resource
199+
200+
```js
201+
var Fetcher = require('fetchr');
202+
var myDataService = {
203+
name: 'serviceResource', // resource
204+
read: function (){}// custom read logic
205+
};
206+
207+
Fetcher.registerFetcher(myDataService);
208+
Fetcher.getFetcher('serviceResource'); // returns myDataService
209+
```
210+
211+
#### middleware
212+
213+
getter for fetchr's express/connect middleware.
214+
215+
```js
216+
var Fetcher = require('fetchr'),
217+
express = require('express'),
218+
app = express();
219+
220+
app.use('/myCustomAPIEndpoint', Fetcher.middleware());
221+
```
222+
223+
### Instance Methods
224+
225+
#### read(resource, params, config, callback)
226+
227+
Call the read method of a service.
228+
229+
#### create(resource, params, body, config, callback)
230+
231+
Call the create method of a service.
232+
233+
#### update(resource, params, body, config, callback)
234+
235+
Call the update method of a service.
236+
237+
#### delete(resource, params, config, callback)
238+
239+
Call the delete method of a service.
240+
[//]: # (API_STOP)
241+
173242
## License
174243

175244
This software is free to use under the Yahoo! Inc. BSD license.

0 commit comments

Comments
 (0)