Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/goschevski/apy
Apy is a simple client-side library for making rest api ajax calls.
https://github.com/goschevski/apy
api browser javascript rest rest-api
Last synced: about 1 month ago
JSON representation
Apy is a simple client-side library for making rest api ajax calls.
- Host: GitHub
- URL: https://github.com/goschevski/apy
- Owner: goschevski
- Created: 2014-05-13T22:31:53.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-08-25T18:00:02.000Z (over 7 years ago)
- Last Synced: 2024-11-04T02:06:32.659Z (about 2 months ago)
- Topics: api, browser, javascript, rest, rest-api
- Language: JavaScript
- Homepage:
- Size: 46.9 KB
- Stars: 67
- Watchers: 7
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Apy
[![Build Status](https://travis-ci.org/goschevski/apy.svg?branch=master)](https://travis-ci.org/goschevski/apy)
Apy is a simple client-side library for making REST API AJAX calls.
It supports both callback and promises.## API
### all ([params], [callback])
#### Params
- **params** *(object)*: serialized and appended as a querystring to the url
- **callback** *(function)*: triggered when the request is done#### Returns
- **promise**: Returns the Promise.### find (id, [params], [callback])
#### Params
- **id** *(string|number)*: id of resource appended to the url
- **params** *(object)*: serialized and appended as a querystring to the url
- **callback** *(function)*: triggered when the request is done#### Returns
- **promise**: Returns the Promise.### save (data, [params], [callback])
#### Params
- **data** *(object)*: sent as body of the request
- **params** *(object)*: serialized and appended as a querystring to the url
- **callback** *(function)*: triggered when the request is done#### Returns
- **promise**: Returns the Promise.### update (id, data, [params], [callback])
#### Params
- **id** *(string|number)*: id of resource appended to the url
- **data** *(object)*: sent as body of the request
- **params** *(object)*: serialized and appended as a querystring to the url
- **callback** *(function)*: triggered when the request is done#### Returns
- **promise**: Returns the Promise.### destroy (id, [params], [callback])
#### Params
- **id** *(string|number)*: id of resource appended to the url
- **params** *(object)*: serialized and appended as a querystring to the url
- **callback** *(function)*: triggered when the request is done#### Returns
- **promise**: Returns the Promise.## Examples
## First define resource
```javascript
var PeopleApi = new Apy({
base: '/api/v3/people'
});
```#### So let's fetch all nice developers
```javascript
PeopleApi.all({ kind: 'nice', job: 'developer' }, function (err, data) {
if (!err) {
console.log(data);
}
});
```*GET* request to `/api/v3/people/?kind=nice&job=developer`
#### Or we can fetch all developers even if they are not nice...
```javascript
PeopleApi.all().then((data) => {
console.log(data);
}).catch((err) => {
console.log(err);
});
```