Skip to content

API Documentation

Demeatrice J. Sherrod edited this page Feb 4, 2021 · 5 revisions

The DejaView API is organized around REST. The API has predictable resource oriented URLs, accepts JSON-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes and verbs.

API routes are not user-facing and should only be used by developers.

Resources:


Users

Endpoints for the Users resource:


Log In

Logs an existing user into the application

POST /api/auth/login

Body Parameters

Parameter Type Description Notes
email string email of the user logging in required
password string password of the user logging in required

Returns

Returns a current user object if successful and sets an HTTP-only auth cookie, and returns an errors object otherwise.


Sign Up

Creates a new user and logs them into the application

POST /api/auth/signup

Body Parameters

Parameter Type Description Notes
name string Desired name of the new user required
email string Desired email of the new user required, unique
password string Desired password of the new user required

Returns

Returns a current user object if successful and sets an HTTP-only auth cookie, and returns an errors object otherwise.


Log Out

Logs out the current user

GET /api/auth/logout

Returns

Returns a logged out message.


Authenticate

Authenticates a user

GET /api/auth/

Path Parameters

Parameter Type Description Notes
id ID id of the user required

Returns

Returns a current user object if successful, and returns an errors object otherwise.


Unauthorized

Returns unauthorized JSON when flask-login authentication fails

GET /api/auth/unauthorized

Returns

Returns an errors object.


Retrieve All Users

Returns all users stored in the database.

GET /api/users

Returns

Returns an array of user objects.


Retrieve Single User

Returns user specified by id provided in URL

GET /api/users/:id

Path Parameters

Parameter Type Description Notes
id ID id of the user required

Returns

Returns a user object.


Retrieve User Dreams

Returns dreams specified by user id provided in URL

GET /api/users/:id/dreams

Path Parameters

Parameter Type Description Notes
id ID id of the user required

Returns

Returns an array of dream objects.


Retrieve User Fragments

Returns fragments specified by user id provided in URL

GET /api/users/:id/fragments

Path Parameters

Parameter Type Description Notes
id ID id of the user required

Returns

Returns an array of fragment objects.


Dreams

Endpoints for the Dreams resource:


Retrieve All Dreams

Retrieves all the dreams

GET /api/dreams

Returns

Returns an array of dream objects if successful, and returns an errors object otherwise


Retrieve a Single Dream

Retrieves a single dream with the specified id

GET /api/dreams/:id

Path Parameters

Parameter Type Description Notes
id ID id of the dream to retrieve required

Returns

Returns a dream object if successful, and returns an errors object otherwise.


Retrieve all Fragments for a Single Dream

Retrieves all fragment objects within a dream with the specified id

GET /api/dreams/:id/fragments

Path Parameters

Parameter Type Description Notes
id ID id of the dream whose fragments are to be retrieved required

Returns

Returns a fragment objects if successful, and returns an errors object otherwise


Create a Dream

Creates a new dream

POST /api/dreams

Body Parameters

Parameter Type Description Notes
title string title of the dream being created required
keywords string keywords of the dream being created required
notes text notes of the dream being created required
created_at datetime date & time of the dream being created required
updated_at datetime date & time of the dream being created required

Returns

Returns the created dream object if successful, and returns an errors object otherwise.


Edit a Dream

Edits an existing dream that the current user is the dreamer of, **requires authentication with a cookie**

PUT /api/dreams/:id

Path Parameters

Parameter Type Description Notes
id ID id of the dream to edit required

Body Parameters

Parameter Type Description Notes
title string title of the dream being edited required
keywords string keywords of the dream being created required
notes text notes of the dream being edited required

Returns

Returns the edited dream object if successful, and returns an errors object otherwise.


Delete a Dream

Deletes an existing dream the current user is the dreamer of, **requires authentication with a cookie**

DELETE /api/dreams/:id

Path Parameters

Parameter Type Description Notes
id ID id of the dream to edit required

Returns

Returns a success message if successful, and returns an errors object otherwise.


Fragments

Endpoints for the Fragments resource:


Retrieve All Fragments

Retrieves all the fragments

GET /api/fragments

Returns

Returns an array of fragment objects if successful, and returns an errors object otherwise


Retrieve a Single Fragment

Retrieves a single fragment with the specified id

GET /api/fragments/:id

Path Parameters

Parameter Type Description Notes
id ID id of the fragment to retrieve required

Returns

Returns an fragment object if successful, and returns an errors object otherwise.


Create a Fragment

Create a new event

POST /api/fragments

Body Parameters

Parameter Type Description Notes
title string title of the fragment being created required
emotions string emotions of the fragment being created required
setting string setting of the fragment being created required
description text description of the fragment being created required

Returns

Returns the created fragment object if successful, and returns an errors object otherwise.


Edit a Fragment

Edits an existing fragment that the current user is the user of, **requires authentication with a cookie**

PUT /api/fragments/:id

Path Parameters

Parameter Type Description Notes
id ID id of the fragment to edit required

Body Parameters

Parameter Type Description Notes
title string title of the fragment being created required
emotions string emotions of the fragment being created required
setting string setting of the fragment being created required
description text description of the fragment being created required

Returns

Returns the edited fragment object if successful, and returns an errors object otherwise.


Delete a Fragment

Deletes an existing fragment of that the current user is the leader of the dream that is hosting the fragment, **requires authentication with a cookie**

DELETE /api/fragments/:id

Path Parameters

Parameter Type Description Notes
id ID id of the fragment to delete required

Returns

Returns a success message if successful, and returns an errors object otherwise.


Objects

Current User Object

{
  "id": 1,
  "username": "Jimmy",
  "email": "jimmy@dejaview.com"
}

User Object

{
  "id": 2,
  "username": "Walker",
  "email": "walker@dejaview.com"
}

Success Message

{
  "message": "success"
}

Logged Out Message

{
  "message": "User logged out"
}

Errors Object

{
  "errors": "errors message here"
}

Dream Object

{
  "id": 41,
  "title": "Jan30 Dream",
  "keywords": "wonder",
  "notes": "car, friend, convenience store, motorcycle, parking lot",
  "user_id": 4,
  "createdAt": "2020-10-18T20:26:34.256Z",
  "updatedAt": "2020-10-18T20:26:34.256Z",
}

Fragment Object

{
  "id": 23,
  "title": "parking lot",
  "emotions": "carefree",
  "setting": "nighttime parking lot",
  "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sed libero quam. In in porta sem, nec bibendum neque. Quisque nec turpis et     libero condimentum tincidunt id eget risus. Aenean lacinia ex quis suscipit maximus. In consequat, arcu a mollis commodo, metus tellus dapibus felis, eu    mattis ipsum elit a risus. Mauris tempor tincidunt ex et ullamcorper. Cras faucibus mauris vel dolor volutpat fringilla.",
  "user_id": 1,
  "createdAt": "2020-10-18T20:26:34.256Z",
  "updatedAt": "2020-10-18T20:26:34.256Z",
}

Clone this wiki locally