Skip to content

Backend API

Reece Adamson edited this page Nov 18, 2020 · 7 revisions

Overview

The pathways backend allows for persistent memory of pathways, criteria, and eventually users. It follows the MERN stack (MongoDB, ExpressJS, React, Node). Since the database can not be run in browser a new server is required to connect to the database. Screen Shot 2020-10-14 at 3 06 08 PM The React frontend will make calls to the server API (using something like axios). The API will link the client requests to persisting the data in the database.

MongoDB

MongoDB is a document-based NoSQL database which stores data as JSON. The Mongoose library is available for a Node app to connect to a MongoDB. Instructions on downloading and running MongoDB can be found here.

Collection Schemas

Collections in Mongo are equivalent to Tables in SQL based databases. There are 3 collections - Pathway, Criteria, and Workspace. The schemas for each collection are identical at the top level:

const schema = new Schema({
        id: String, // The id of the artifact.  The same id as value.id
	metadata: Object, // Key value pairs for storing metadata (e.g. the owner of the pathway)
	value: Object // The actual JSON mapping to the pathway, criteria or workspace model
});

The subdocuments in the value field align with the respective data models used in the frontend

Note: Before user authentication is implemented the User and Workspace collections will not exist. The userid property on Pathway and Criteria will also not exist yet.

API

Service Method Description
/pathway?id={pathwayid}&user={userid}&workspace={workspaceid} GET Gets a list of all the pathways matching the conditions. Each query param is optional. Once user authentication is added it will only return pathways which the user has access to. Returns 200 OK on success or 403 FORBIDDEN.
/pathway/id PUT Updates the specific pathway. Body is the new Pathway. If id does not exist, create a new pathway and return 201 CREATED. Returns 200 OK on success, 403 FORBIDDEN if not authorized, and 404 NOT FOUND if pathway with id id does not exist.
/pathway/id DELETE Deletes the specific pathway. No body. Returns 200 OK on success.
/criteria?id={criteriaid}&user={userid}&workspace={workspaceid} GET Gets a list of all the criteria matching the conditions. Each query param is optional. Once user authentication is added it will only return criteria which the user has access to. Returns 200 OK on success or 403 FORBIDDEN.
/criteria/id PUT Updates the specific pathway. Body is the new Criteria. If id does not exist, create a new criteria and return 201 CREATED. Returns 200 OK on success, 403 FORBIDDEN if not authorized, and 404 NOT FOUND if criteria with id id does not exist.
/criteria/id DELETE Deletes the specific criteria. No body. Returns 200 OK on success.
/workspace?id={workspaceid} GET Gets a list of all the workspaces matching the conditions. Each query param is optional. Once user authentication is added it will only return workspaces which the user has access to. Returns 200 OK on success or 403 FORBIDDEN.
/workspace POST Creates a new workspace in the database. Body is the new workspace. Returns 201 CREATED on success.
/workspace/id PUT Updates the specific workspace. Body is the new workspace. Returns 200 OK on success, 403 FORBIDDEN if not authorized, and 404 NOT FOUND if workspace with id id does not exist.
/user?id={userid} GET Gets a list of all users matching the conditions. Each query param is optional. Returns 200 OK on success.
/user POST Creates a new user in the database. Body is the new user. Returns 201 CREATED on success.
/auth/login POST Attempt to authorize a user. Body is the user (email and password). On success starts a new server session and returns 200 SUCCESS.
Clone this wiki locally