Giter Site home page Giter Site logo

bitsick / redux-coreapi Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 162 KB

A minimal interface between Redux and Core API JavaScript clients.

License: Apache License 2.0

Python 6.94% HTML 2.66% JavaScript 89.93% CSS 0.46%
javascript redux coreapi django django-rest-framework rest-api

redux-coreapi's Introduction

redux-coreapi

redux-coreapi is a minimal interface between Redux and Core API JavaScript clients. More specifically, redux-coreapi dispatches Redux actions for Core API action and document request-response cycles, allowing Core API clients to be integrated simply into Redux applications.

Getting Started

Prerequisites

redux-coreapi does not have any prerequisites or direct dependencies, but it is assumed that it will be used alongside redux and coreapi.

Installation

Install with npm

$ npm i redux-coreapi

or yarn

$ yarn add redux-coreapi

Usage

Begin by applying the redux-coreapi middleware to the store. For example:

import { createStore, applyMiddleware } from 'redux'
import { coreapiMiddleware } from 'redux-coreapi'
import reducer from './reducer'

const store = createStore(
  reducer,
  applyMiddleware(coreapiMiddleware)
)

Use the get and action action creators to make Core API document and action requests, respectively.

import coreapi from 'coreapi'
import { action, get } from 'redux-coreapi'
import document from './path/to/existing/document'

const client = new coreapi.Client()

// Load a Core API schema document
store.dispatch(get(client, 'https://example.com/api/v1/schema'))

// Send a request to create a new object
store.dispatch(action(
  client,
  document,
  ['objects', 'create'],
  {
    name: 'Example',
    description: 'redux-coreapi example object',
  }
))

API

Full API documentation is available in docs/api.md file or at https://bitsick.github.io/redux-coreapi/api.md.

get(client, url)

Make a Core API document request.

Parameters

  • client (coreapi.Client) The Core API client instance with which the request will be made.
  • url (string) The URL of the document to request.

Returns

(Object) A Redux action for the Core API get request.

action(client, document, keys, [params])

Make a Core API action request.

Parameters

  • client (coreapi.Client) The Core API client instance with which the request will be made.
  • document (coreapi.Document) The Core API document describing the API to which the request will be sent.
  • keys (string[]) An array of strings describing the action to request. For example, ["users", "list"] or ["widgets", 0, "update"].
  • [params] (Object) Optional data to include with the request. The structure of the object depends on the action being requested.

Returns

(Object) A Redux action for the Core API action request.

Examples

See the example directory for a complete working example.

Contributing

See CONTRIBUTING.md for details on making contributions.

Versioning

This repository uses GitFlow and semantic versioning. See the tags in the master branch for the available versions.

License

Apache License 2.0

redux-coreapi's People

Contributors

ajmatsick avatar

Stargazers

 avatar  avatar

Watchers

 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.