A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/milroyfraser/sarala below:

milroyfraser/sarala: Javascript library to communicate with RESTful API built following JSON API specification. inspired by Laravel’s Eloquent

Javascript library to communicate with RESTful API built following JSON API specification. inspired by Laravel’s Eloquent

import { Model } from 'sarala';
import axios from 'axios';

export default class BaseModel extends Model
{
    baseUrl () {
        return 'https://sarala-demo.app/api';
    }

    request (config) {
        return axios.request(config);
    }
}
import Model from './BaseModel';
import Tag from './Tag';

export default class Post extends Model {
    resourceName () {
        return 'posts';
    }

    fields () {
        return ['title', 'subtitle', 'body', 'slug'];
    }

    relationships () {
        return {
            tags: new Tag()
        };
    }
}
import Model from './BaseModel';

export default class Tag extends Model {
    resourceName () {
        return 'tags';
    }

    fields () {
        return ['name'];
    }
}
import Post from './../models/Post';

const post = new Post();

// makes a GET request to https://sarala-demo.app/api/posts
const fetchAllPosts = async () => {
    let posts = await post.with(['tags']).all();
};
app/components/MyComponent.js
import Tag from './../models/Tag';

const tag = new Tag();
tag.name = 'json-api';

// makes a POST request to https://sarala-demo.app/api/tags
tag.save(); 
// or you can directly call tag.create();

Please see CHANGELOG for more information on what has changed recently.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4