sarala
Version:
Javascript library to communicate with RESTful API built following JSON API specification. inspired by Laravel’s Eloquent.
56 lines (41 loc) • 679 B
Markdown
---
sidebarDepth: 0
---
```bash
$ yarn add sarala
```
```bash
$ npm i sarala --save
```
```javascript
import { Model } from 'sarala'
import axios from 'axios'
export default class Post extends Model
{
baseUrl () {
return 'https://api.example.com'
}
request (config) {
return axios.request(config)
}
resourceName () {
return 'posts'
}
fields () {
return ['title', 'subtitle', 'body', 'slug']
}
}
```
```javascript
import Post from './Post'
// ...
const post = new Post()
const data = await post.find(id)
// ...
console.log(data.slug)
```