Skip to content
master
Switch branches/tags
Code
This branch is 2 commits ahead of Buildweek-guidr/backend:master.
Contribute

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Guidr Backend - API & Database

API and Database code for a Lambda School project. I was assigned as the sole backend developer on a project called Guidr. It was an application that allowed for a professional guide to showcase their skills and build a resume of previous trips they have taken people on. They can log the individual trips and show information about them for how long the trip was for, the type of trip, the location, as well as distance covered. I was tasked with building a backend API and database to support user login/registration and CRUD actions on trips. I worked together with a team of two React devs making a web client and an iOS dev making a mobile client.

This project is used as a portfolio piece for my work as a Software Developer. If you are interested in discussing this further with me please feel free to reach out on Twitter or on my website.

License

This project is licensed under the terms of the MIT license. For more details see the LICENSE file.

Contribution

This project isn't currently taking contributions, but I am happy to hear feedback. If you have feedback or if there is anything you would like to see changed please open an issue. You are welcome to fork this project to work on your own version. Feel free to reach out if you have any questions for me.

Documentation

Base URL: https://guidr-backend-api.herokuapp.com/api //depends on deployment

Checking this in a browser or making a GET request to it directly should return a JSON object like this:

{
    status: "It's Alive!"
}

Authentication

All endpoints except for Login and Register will require Authentication by the client. Any client (web or mobile) will need to authenticate their requests by placing a token as the value for the Authorization header. A token property is returned in the response on both the Login and Register requests and does not expire for 7 days.

The token for a user can only be used to performs actions for that user specifically. Requests made to trips or profile owned by a user from a token generated by a different user will receive the 401 status code. In the response will be an object with an error property.

Profile

{ error: 'Access to this user data is unauthorized' }

Trips

{ error: 'Access to this trip data is unauthorized' }

Errors

When errors occur with the requests a json object will be returned with an error property containing information on what error occurred.

{
  error: <ERROR_STRING_TEXT>
}

Endpoints

Summary

Route Method Description Requires Auth
/accounts/login POST Send user credentials to login to the application No
/accounts/register POST Send user information to register a new user with the application No
/users/:userId/trips GET Retrieve all of the trips for a particular user by their userId Yes
/trips/:tripId GET Retrieve data of a specific trip by using its unique id Yes
/trips/:tripId PUT Update the data of a single trip by its unique id Yes
/trips/:tripId DELETE Delete a single trip by its unique id Yes
/trips POST Add data of a new trip for a user Yes
/users/:userId/profile GET Retrieve profile data of a specific user by the user id Yes
/users/:userId/profile PUT Update profile data of a specific user by the user id Yes
/users/:userId/profile/public GET Retrieve public profile data of a specific user by the user id No

User Accounts


Login

Route:
/accounts/login

Method:
POST

Description:
Send user credentials to login to the application

Body:

{ "username": STRING, "password": STRING }

Returns:
User Login Object

{ "userId": INTEGER, "username": STRING, "token": STRING }

Register

Route:
/accounts/register

Method:
POST

Description:
Send user information to register a new user with the application

Body:

{
    "username": STRING,
    "password": STRING,
    "title": STRING,
    "tagline": STRING,
    "guideSpecialty": STRING,
    "age": INTEGER,
    "yearsExperience": INTEGER
}

NOTE: only the username and password properties are required for registration. All other properties can be left out of the object. Any omitted properties will be null in the response and can be updated later.

Returns:
Registered User Object

{
  "user": {
    "id": INTEGER,
    "username": STRING,
    "title": STRING,
    "tagline": STRING,
    "guideSpecialty": STRING,
    "age": STRING,
    "yearsExperience": STRING
  },
  "token": STRING
}

Trips


Get User Trips

Route:
/users/:userId/trips

Method:
GET

Description:
Retrieve all of the trips for a particular user by their userId

Returns:
Array of trip objects. By default the trip objects are sorted in ascending order by the date property.

[
  {
    "id": INTEGER,
    "title": STRING,
    "isPrivate": BOOLEAN,
    "isProfessional": BOOLEAN,
    "image": STRING, //Image URL to be used as src of the image
    "duration": FLOAT,
    "distance": FLOAT,
    "date": DATE,
    "tripType": STRING
  }
]

NOTE: If user has not trips this will return an empty array.


Get Trip by Id

Route:
/trips/:tripId

Method:
GET

Description:
Retrieve data of a specific trip by using its unique id

Returns:
A single trip object

{
  "id": INTEGER,
  "title": STRING,
  "isPrivate": BOOLEAN,
  "isProfessional": BOOLEAN,
  "image": STRING, //Image URL to be used as src of the image
  "duration": FLOAT,
  "distance": FLOAT,
  "date": DATE,
  "tripType": STRING
}

Update Trip By Id

Route:
/trips/:tripId

Method:
PUT

Description:
Update the data of a single trip by its unique id

Body:

{
    "id": INTEGER,
    "title": STRING,
    "isPrivate": BOOLEAN,
    "isProfessional": BOOLEAN,
    "image": STRING, //Image URL to be used as src of the image
    "duration": FLOAT,
    "distance": FLOAT,
    "date": DATE,
    "tripType": STRING
}

NOTE: Only the properties of the object that need to be updated should be provided in the body of the request.

Returns:
The updated trip object

{
  "id": INTEGER,
  "title": STRING,
  "isPrivate": BOOLEAN,
  "isProfessional": BOOLEAN,
  "image": STRING, //Image URL to be used as src of the image
  "duration": FLOAT,
  "distance": FLOAT,
  "date": DATE,
  "tripType": STRING
}

Delete Trip By Id

Route:
/trips/:tripId

Method:
DELETE

Description:
Delete a single trip by its unique id

Returns:
The trip object of the deleted trip

{
  "id": INTEGER,
  "title": STRING,
  "isPrivate": BOOLEAN,
  "isProfessional": BOOLEAN,
  "image": STRING, //Image URL to be used as src of the image
  "duration": FLOAT,
  "distance": FLOAT,
  "date": DATE,
  "tripType": STRING
}

Add Trip

Route:
/trips

Method:
POST

Description:
Add data of a new trip for a user

Body:

{
    "id": INTEGER,
    "title": STRING, // **REQUIRED**
    "isPrivate": BOOLEAN,
    "isProfessional": BOOLEAN,
    "image": STRING, //Image URL to be used as src of the image
    "duration": FLOAT,
    "distance": FLOAT,
    "date": DATE,
    "tripType": STRING,
    "user_id": INTEGER // **REQUIRED** Id of the user the trips belongs to.
}

NOTE: The only two properties that are required when creating a new trip is the title and the user_id. Other properties can be omitted and updated later.

Returns:
The newly created trip object

{
  "id": INTEGER,
  "title": STRING,
  "isPrivate": BOOLEAN,
  "isProfessional": BOOLEAN,
  "image": STRING, //Image URL to be used as src of the image
  "duration": FLOAT,
  "distance": FLOAT,
  "date": DATE,
  "tripType": STRING
}

User Profile


Get User Profile

Route:
/users/:userId/profile

Method:
GET

Description:
Retrieve profile data of a specific user by the user id

Returns:
User profile object

{
  "id": INTEGER,
  "username": STRING,
  "title": STRING,
  "tagline": STRING,
  "guideSpecialty": STRING,
  "age": INTEGER,
  "yearsExperience": INTEGER
}

Update User Profile

Route:
/users/:userId/profile

Method:
PUT

Description:
Update profile data of a specific user by the user id

Body:

{
  "title": STRING,
  "tagline": STRING,
  "guideSpecialty": STRING,
  "age": INTEGER,
  "yearsExperience": INTEGER
}

NOTE: Only the properties of the object that need to be updated should be provided in the body of the request.
The id and username properties cannot be updated and should not be included in the request body.

Returns:
Updated User profile object

{
  "id": INTEGER,
  "username": STRING,
  "title": STRING,
  "tagline": STRING,
  "guideSpecialty": STRING,
  "age": INTEGER,
  "yearsExperience": INTEGER
}

About

Backend API and Database for a React client

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published