Code Monkey home page Code Monkey logo

contract-driven-api's Introduction

Contract-driven API

This minimal proof of concept demonstrates a pattern to code REST APIs that allows for a client-server communication that is less error prone, faster to code, and more powerful.

Why

Usually there is only a few types of HTTP exchange that can happen: authenticated POST request, non-authenticated GET request, file upload, etc. They should be implemented only once.

Which API route exists and how it looks like should not be a matter of code. This information should reside in a configuration object - the contract - that is shared between the client and the server.

How

The concept resides in having the following components:

  • API contract: contains routes (aka API endpoins) informations:
    • Which routes exist
    • How they behave
    • How input and output look like
  • For each type of HTTP exchange there is
    • a generic caller in the client
    • a generic responder in the server
  • Only valid API calls are exposed and allowed, through:
    • An api object in the client
    • A router object in the server
    • These should not change if a route is added, deleted or modified

What

This repository is an implementation of the contract-driven API pattern explained above. It consist in a tasklist app: a user sign up, log in, and gain the right to edit a task list.

The types of HTTP exchanges are:

  • default post, for signup and login
  • authenticated get, to retrieve the tasks
  • authenticated post, to save the tasks

The pattern code components described above can be found as follow:

Stack:

Run locally:

git clone [email protected]:ninofiliu/contract-driven-api
cd contract-driven-api
npm install
npm run build
npm run start

contract-driven-api's People

Contributors

ninofiliu avatar dependabot[bot] avatar

Stargazers

Jordan Maddock avatar

Watchers

James Cloos 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.