Code Monkey home page Code Monkey logo

router-api's Introduction

Router API

This provides an API for updating the routes used by the router.

Technical documentation

A Ruby on Rails application that manages the router database. Routes are stored in a mongo database using Mongoid as an ORM.

Dependencies

When running in development mode, this will ignore connection errors when triggering a reload of the router

Running the application

bundle exec rails s

The app will then be available at http://localhost:3000/ (the port can be changed by passing a -p option to the command)

Running the test suite

bundle exec rake

API endpoints

Routes

Information about the route data structure can be found in the router repository.

Getting details of a route:
curl "http://router-api.example.com/routes?incoming_path=/foo"

This will return the corresponding route in JSON format.

Creating/updating a route:

The following will create/update a route entry:

curl http://router-api.example.com/routes -X PUT \
    -H 'Content-type: application/json' \
    -d '{"route": {"incoming_path": "/foo", "route_type": "exact", "handler": "backend", "backend_id": "foo"}}'

This will return details of the updated route in JSON format. If the route doesn't already exist, it will be created and a 201 status code returned. The backend_id must reference a backend that exists (see below).

On error a 400 status code will be returned, and the JSON response will include an "errors" key with more details.

Deleting a route:
curl "http://router-api.example.com/routes?incoming_path=/foo" -X DELETE

This will delete the corresponding route. If no route matches the JSON request, a 404 status code will be returned.

Committing changes:
curl http://router-api.example.com/routes/commit -X POST

This will trigger a router reload and cause any changes to the route to take effect.

Backends

Backends represent an application that the router can route requests to. They are referenced by entries in the routes collection. Information about the backend data structure can be found in the router repository.

Getting details for a backend:
curl http://router-api.example.com/backends/foo

Will return the backend details in JSON format.

Creating/updating a backend:
curl http://router-api.example.com/backends/foo -X PUT \
    -H 'Content-type: application/json' \
    -d '{"backend": {"backend_url": "http://foo.example.com/"}}'

This will update the backend_url for the backend with id 'foo'. The backend entry will be created if it doesn't already exist (and a 201 status code returned). The response will be a JSON representation of the updated backend.

On validation error a 400 status code will be returned, and the resulting JSON document will have an "errors" key with more details.

Deleting a backend:
curl http://router-api.example.com/backends/foo -X DELETE

This will delete the backend with id 'foo'. This will only be allowed if the backend has no associated routes. A 400 status code will be returned if this is the case.

Licence

MIT License

router-api's People

Contributors

ajlanghorn avatar alexmuller avatar alext avatar benilovj avatar benlovell avatar bishboria avatar boffbowsh avatar bradwright avatar danielroseman avatar dcarley avatar dougdroper avatar elliotcm avatar jabley avatar jackscotti avatar mattbostock avatar mnowster avatar steventux avatar timmow avatar tombooth avatar vinayvinay avatar

Watchers

 avatar  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.