Skip to content

Routes and APIs

Song Zheng edited this page May 28, 2020 · 7 revisions

Introduction

We need the following routes and API endpoints to power the following pages:

  • Landing
  • Login
  • Signup
  • Email Confirmation
  • Database Setup
  • Databases

Routes

The follow routes would be needed to power the pages above

/login

Renders the login page

/signup

Renders the signup page

/

  • Renders landing page if user is not logged in
  • Renders render email confirmation page if user has not confirmed email.
  • Renders database setup page if user has not created a database password.
  • Renders the databases page

/logout

Destroys user's session cookies and redirects to / landing page.

APIs you need

POST /api/session

Used by:

  • Login Page

Request body

passwords are base64 encoded so that if engineers are debugging something in production, they don't accidentally see each other's password.

{
  email: '[email protected]',
  password: 'base64 encoded password'
}

Response

Success

{
  status: 'success' 
}

Error

{
  error: {
    messages: ["username / password combination is not valid"]
  }
}

POST /api/users

Used by

Request Body

{
  username: 'username',
  password: 'base64 encoded password',
  email: '[email protected]'
}

Response

Success

{
  status: 'success'
}

Error

{
  error: {
    message: ["username is taken", "password is too short", "email is invalid"]
  }
}

POST /api/notification

Used by

Request Body

{
  type: 'email',
  category: 'resetPassword',
  email: '[email protected]'
}

Response

Success

{
  status: 'success'
}

Error

{
  error: {
    message: 'Email delivery failed. Please try again.'
  }
}

PATCH /api/users/:id

This updates the user with a database password for that user to use to create all databases.

Used By

Request body

{
  password: 'base64 encoded password'
}

Response

Success

{
  status: 'success'
}

Error

{
  error: {
    message: 'database setup failed'
  }
}

POST /api/users/:id/databases

Create a database for the currently logged in user

Used by:

Request Body

base64 encoded JSON string
{
  name: 'postgres'
}

Response

Success

{
  status: 'success' 
}

Error

{
  error: {
    message: 'failed to create database'
  }
}

GET /api/databases

Get all databases for the currently logged in user.

Used by:

Response

Success

{
  data: [{postgres: {connectionInfo:{...}}}, {mongoDB: {connectionInfo:{...}}, {neo4J: {connectionInfo: null}}}] 
}

Error

{
  error: {
    message: 'failed to get databases'
  }
}