Giter Club home page Giter Club logo

frontend-backend-api's Introduction

frontend-backend-api

Designed for sinchronization frontend data with backend data.
Was inspired by idea to take out synchronization api from backbone collection and model.

Usecases

import backend from 'my-backend-instance';
import dataModel from 'my-data-model';

// Fetch data from backend and synchronize dataModel
backend.fetch(dataModel); 

// Sends new data to backend
backend.save(dataModel);

// delete the model on backend and destroy the modelData on success.
backend.delete(dataModel);

Default implementation

Is ready for use and backend communications are based on fetch

import { BackendApi } from 'frontend-backend-api';
export const backend = new BackendApi();

Using jQuery ajax

By default you may omit buildSendRequestArguments

import { BackendApi } from 'frontend-backend-api';
import $ from 'jquery';
export const jqueryBackend = new BackendApi({ jquerySend: $.ajax });

But in case you need your own, just provided it:

import { BackendApi } from 'frontend-backend-api';
import $ from 'jquery';

function buildSendRequestArguments(options) {
    let args = [];
    // prepare arguments by your own
    // if you need default arguments you can call super
    // in case of jquery it will produce array with jquery ajax options
    // otherweise fetch options
    

    return args;
}

export const backend = new BackendApi({ jquerySend: $.ajax, buildSendRequestArguments });

Using Backbone.sync

By default you may omit buildSendRequestArguments

import { BackendApi } from 'frontend-backend-api';
import Backbone from 'backbone';

export const backboneBackend = new BackendApi({ sendRequest: Backbone.sync });

In case you need own buildSendRequestArguments just provide it

import { BackendApi } from 'frontend-backend-api';
import Backbone from 'backbone';

function buildSendRequestArguments(options)
{
    // to do: explain better the case with Backbone.sync
    return [method, model, options]
}

export const backboneBackend = new BackendApi({ sendRequest: Backbone.sync, buildSendRequestArguments });

Using your own send mechanic

import { BackendApi } from 'frontend-backend-api';

function mySendRequest(...sendRequestArguments) {
    // ....
}

function buildSendRequestArguments(options) {
    let sendRequestArguments = [ ... ];
    return sendRequestArguments;
}

export const customBackend = new BackendApi({ sendRequest: mySendRequest, buildSendRequestArguments });

frontend-backend-api's People

Contributors

taburetkin avatar

Watchers

James Cloos avatar Julian Gonggrijp avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.