Code Monkey home page Code Monkey logo

api-express's Introduction

api-express

api-express is an attempt to come up with universal language for defining and documenting HTTP APIs using JSX.

Ultimately, api-express allows you to define the structure of your API service in JSX. Using this definition, api-express is able to run the service, validate request and response formats and generate documentation for your service. The definition is a live JavaScript code which allows changing the additional features (docs/validation/formats etc) of your API service without changing the application parts.

Example

This file defines a service which is able to deliver user data by GET /users/:id.

/** @jsx ApiExpress.h */

import ApiExpress, {
  Service,
  Middleware,
  Group,
  Route,
  Request,
  Response,
  PathParameter,
} from '.';

export default function() {
  return <Service
    id="my-service"
    port={3000}
    version="0.1.0"
    contact="Alex"
    tags={['node', 'service']}
    endpoint="http://dev.server.at.home"
  >
    <Middleware use={require('./middleware/logger')} />
    <Group name="Users" description="All about users">
      <Route path="/users/:id" method="get" handler={require('./handlers/getUserById')}>
        <Request>
          <PathParameter name="id" type="string" />
        </Request>
        <Response schema={require('./schemas/getUserById.res.json')} />
      </Route>
    </Group>
  </Service>;
}

To run this definition with express, simply call run:

const { run } = require('.');
const serverDef = require('./definition').default;
run(serverDef());

To generate documentation in API blueprint format, simply call doc:

const { doc } = require('.');
const serverDef = require('./definition').default;
doc(serverDef(), (err, docs) => {
  require('fs').writeFileSync('./api.doc', docs, 'utf-8');
});

The result is here.

Status

Experimental/Proof-Of-Concept. There is a lot of work to be done in standardizing the elements available and documenting what they mean to make sure enough use cases can be covered. Also implementation must be completed and an internal architecture has to be established.

LICENSE

MIT

api-express's People

Contributors

orkon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

seactjs

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.