Project Butterfly: Generating a REST API

Trying to get this project moving again, Project Butterfly needs a REST API to work as a functional example of contract-based web services which can scale to, theoretically, millions.  Using the schema presented earlier, a set of REST API contracts for a front end to a backend.

If we were going for serious node.js scaling at the service layer and building this system for production, this contract divides fairly cleanly into a user controller and a conventions controller.  Splitting apart services we could build:

  • An account service focused on user creation and account management.
  • A reservations service focused on convention creation, pass creation, and reserving a seat.  Also, even more interestingly, we do not have to reserve a seat in-line -- but that's a later topic.
  • A search service.

As an example these are all one service.  A quick implementation note: the schema should be updated with a flag to mark deletion but not delete data out of the database.  Deletions lead to lost data and fragmentation.

USERS MODEL API

GET /users -- Get all users
GET /users/:id -- Get user with id = :id
POST /users -- Create user, return ID
PUT /users/:id -- Update user with id = :id
DELETE /users/:id -- Mark user depreciated with id = :id 

CONVENTIONS MODEL API

GET /conventions -- Get all conventions
GET /conventions/:id -- Get all conventions at id = :id
POST /conventions -- Create convention, return ID
PUT /conventions/:id -- Update convention with id=:id
DELETE /conventions/:id -- Mark convention depreciated with id = :id 

CONVENTION PASS TYPES API

GET /conventions/:id/types -- Get all pass types for a convention
GET /conventions/:id/types/:id -- Get information about pass type :id
POST /conventions/:id/types/:id -- Create new pass type :id
PUT /conventions/:id/types/:id -- Update pass type :id
DELETE /conventions/:id/types/:id -- Mark a pass type depreciated

ASSOCIATIONS API

GET /conventions/:id/users -- Get all the users for a convention
GET /conventions/:id/type/:id/count -- Get the total users for a convention's pass type.
GET /conventions/:id/type/:id/max -- Get the total users for a convention's pass type.
GET /conventions/:id/type/:id/users -- Get the list of users for a convention's pass type.
POST /conventions/:id/type/:id/users/:id -- Add a user to a convention's day pass type
PUT /conventions/:id/type/:id/users/:id        Update a user to a convention's day pass type
DELETE /conventions/:id/type/:id/users/:id        Remove a user from a convention's day pass type

VERBS:

GET /search?users=:email  -- Search for user with email = :email
GET /search?conventions=:name  -- Search for convention with name = :name

The REST calls inform the schema.  A convention has a set of passes which have users associated with those passes.  Notes:

  • Count and Max calls are performance killers.  They must be cached.
  • Convention ID must be indexed everywhere it is not primary key.