Skip to content
This repository was archived by the owner on May 4, 2019. It is now read-only.

Backend API

Brad Glaser edited this page Jan 28, 2019 · 16 revisions

/api/login

POST

Logs a user in with the given credentials.

Expects a json body containing the login credentials.

{
  "username": "leinecker01",
  "password": "foobar"
}

Returns 200 OK and sets a token cookie on success.

Returns 401 Unauthorized if the login fails.

/api/logout

POST

Logs a user out with the given token.

Expects the user is logged in and the token cookie is set.

Returns 200 OK if the user was logged out.

Returns 401 Unauthorized if the token is malformed.

/api/register

POST

Creates an account for the given credentials.

Expects a json body containing the login credentials.

{
  "username": "leinecker01",
  "password": "foobar"
}

Returns 200 OK and sets the token cookie.

Returns 409 Conflict if a user already exists with that username.

/api/contacts

GET

Gets all the contacts associated with the given login token.

Expects the token cookie to be correctly set.

Returns 200 OK and a json list of the contacts for the given token if logged in.

[
  {
    "id": "1j4Fqp",
    "firstName": "bob",
    "lastName": "dole",
    "phoneNumber": "4075559999",
    "email": "dummy@fakemail.net"
  },
  {
    "id": "2rjp1Pq",
    "firstName": "jim",
    "lastName": "henson",
    "phoneNumber": "4075558888",
    "email": "elmo@fakemail.net"
  }
]

Returns 401 Unauthorized if the login token is malformed or expired.

/api/contacts

POST

Creates a new contact in the database for the user corresponding to the given login token.

Expects a json body containing a single new contact for the logged in user and a valid token cookie.

{
  "firstName": "bob",
  "lastName": "dole",
  "phoneNumber": "4075559999",
  "email": "dummy@fakemail.net"
}

Returns a json body containing the id of the created contact.

{
  "id": "1j4Fqp"
}

Returns 401 Unauthorized if the login token is malformed or expired.

/api/contacts/<id>

DELETE

Deletes a contact with the given id.

Expects the token cookie to be correctly set.

Returns 200 OK on successful deletion.

Returns 401 Unauthorized if the login token is malformed or expired.

Returns 404 Not Found if no contact exists with the given id for the logged in user.

/api/contacts/<id>

PUT

Updates a contact with given id.

Expects a json body containing the contact's updated details and a valid token cookie.

{
  "firstName": "bob",
  "lastName": "dole",
  "phoneNumber": "4075559999",
  "email": "dummy@fakemail.net"
}

Returns 200 OK on successful update.

Returns 401 Unauthorized if the login token is malformed or expired.

Returns 404 Not Found if no contact exists with the given id for the logged in user.

Clone this wiki locally