Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ebeagusamuel/career_coaches_backend_api

This is a Ruby on Rails API from which the React frontend serves the data. It is a simple Rails app that has three models - User, Coach, and Appointment. For the authentication of the users, I used JSON Web Tokens. The API is hosted on Heroku, and can only be accessed with a valid API token.
https://github.com/ebeagusamuel/career_coaches_backend_api

api jwt rails-api rspec-rails

Last synced: 12 days ago
JSON representation

This is a Ruby on Rails API from which the React frontend serves the data. It is a simple Rails app that has three models - User, Coach, and Appointment. For the authentication of the users, I used JSON Web Tokens. The API is hosted on Heroku, and can only be accessed with a valid API token.

Awesome Lists containing this project

README

        

# BACC(Book a Career Coach)-API

> This is a Ruby on Rails API from which the React frontend serves the data. It is a simple Rails app that has three models - User, Coach and Appointment. For the authentication of the users I used JSON Web Tokens. The API is hosted on Heroku, at this endpoint: [career-coaches-api](https://career-coaches-api.herokuapp.com) - But they can only be accessed with a valid API token. The front end can be found [here](https://github.com/ebeagusamuel/career_coaches_frontend)

## Built With

- Ruby v2.7.0
- Ruby on Rails 6.0.3.4
- Rspec
- JWT

## API Documentation
> The base URL for all the endpoints is `https://career-coaches-api.herokuapp.com`. All request sent to any of the end-points excepts `/users` and `/login` are first validated. The validation is done using tokens generated by JWT upon registration or login. These token has to be sent in the headers of the request you are making in order to successfully access those end-points.

### Register
This API endpoint is used for registering new users to the system and doesn't require authorization.
#### Endpoint
`https://career-coaches-api.herokuapp.com/users`
#### Sample Request
````
curl -X POST \
https://career-coaches-api.herokuapp.com/users \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d 'username=username&email=email&password=password'
````
#### Sample Response
````
{
"user": {
"id": 1,
"email": "email",
"username": "username",
"password_digest": "$2a$12$N.nStVsShl06Y4ClZrazduac91SIp1GMPTwD1/CXLO31RdMtuX1ZK",
"created_at": "2020-11-06T20:06:34.492Z",
"updated_at": "2020-11-06T20:06:34.492Z"
},
"token": "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjozNX0.nLY4f5bGd_E9dJcpp-p1YdDcbaKasVj9hrP3zlfCkdE"
}
````

### Login
This API endpoint is used for logging in a user into the system and also does not require authorization, just the username and password that was used in creating an account and that will be added to the request body.
#### Endpoint
`https://career-coaches-api.herokuapp.com/login`
#### Sample Request
````
curl -X POST \
https://career-coaches-api.herokuapp.com/login \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d 'username=username&password=password'
````
#### Sample Response
````
{
"user": {
"id": 1,
"email": "email",
"username": "username",
"password_digest": "$2a$12$pljN0EuO4Ui/FoKdVfgBhuXkrOEZSTSAHx/KKN8kOUk35IqGm7lwq",
"created_at": "2020-11-01T12:48:45.667Z",
"updated_at": "2020-11-01T12:48:45.667Z"
},
"token": "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.oT7kSePnYs7eVIsRIzIi0UEC7XBclsrO3qrnXwic8Zg"
}
````
### auto_login
This API endpoint is used for automatically logging in a user. It's a get request and reqquires the token generated when the user was created or logged in to be sent along in the request header.
#### Endpoint
`https://career-coaches-api.herokuapp.com/login`
#### Sample Request
````
curl -X GET \
https://career-coaches-api.herokuapp.com/auto_login \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'Authorization: Bearer '
````
#### Sample Response
````
{
"user": {
"id": 1,
"email": "email",
"username": "username",
"password_digest": "$2a$12$pljN0EuO4Ui/FoKdVfgBhuXkrOEZSTSAHx/KKN8kOUk35IqGm7lwq",
"created_at": "2020-11-01T12:48:45.667Z",
"updated_at": "2020-11-01T12:48:45.667Z"
},
}
````
### Get Appointments
This API endpoint return all the appointments of the user.
#### Endpoint
`https://career-coaches-api.herokuapp.com/appointments`
#### Sample Request
````
curl -X GET \
https://career-coaches-api.herokuapp.com/appointments \
-H 'Authorization: Bearer ' \
-H 'cache-control: no-cache' \
````
#### Sample Response
````
[
{
"id": 1,
"user_id": 1,
"coach_id": 3,
"date_and_time: "021-01-08T14:00:00.000Z",
"created_at": "2020-11-01T12:51:04.679Z",
"updated_at": "2020-11-01T12:51:04.679Z"
},
{
"id": 2,
"user_id": 1,
"coach_id": 5,
"date_and_time: "021-01-08T14:00:00.000Z",
"created_at": "2020-11-01T12:51:04.679Z",
"updated_at": "2020-11-01T12:51:04.679Z"
}
]
````
### Book Appointment
This is the API endpoint related to booking appointments in the system.
#### Endpoint
`https://career-coaches-api.herokuapp.com/appointments`
#### Sample Request
````
curl -X POST \
https://career-coaches-api.herokuapp.com/appointments \
-H 'Authorization: Bearer ' \
-H 'cache-control: no-cache' \
-d 'coach_id=2&date=021-01-08T14:00:00.000Z'
````
#### Sample Response
- If the appointment was created:
````
{
"message": "Appointment with Hobert Johnston created successfully."
}
````
- if there was an error:
```
{
"error": "This will be the error message"
}

```
### Cancel Appointment
This is the API endpoint related to cancelling appointments in the system.
#### Endpoint
`https://career-coaches-api.herokuapp.com/appointments/:id`
#### Sample Request
````
curl -X POST \
https://career-coaches-api.herokuapp.com/cancel_appointment/:id \
-H 'Authorization: Bearer ' \
-H 'cache-control: no-cache' \
-d 'coach_id=2'
````
#### Sample Response

```
{
"message": "Your appointment with Hobert Johnston has been cancelled."
}
```

## Getting Started

To get a local copy up and running follow these simple example steps.

### Prerequisites

Ruby: 2.7.0
Rails: 6.0.3.4
Postgres: >=9.5

### Setup

Install gems with:

```
bundle install
```

Setup database with:

```
rails db:create
rails db:migrate
```

Populate database with:

```
rails db:seed
```

### Usage

Start server with:

```
rails server
```

- You can then proceed to test the different end point via postman or any choice of yours.

### Run tests
Type the following in your terminal/command line to run tests for the API:
```
rpsec
```

### Deployment

This API has been deployed on [heroku.](https://www.heroku.com) It is acccessible at `https://career-coaches-api.herokuapp.com/`.

## Author

👤 **Ebeagu Samuuel**

- Github: [ebeagusamuel](https://github.com/ebeagusamuel)
- Twitter: [@ebeagu_samuel](https://twitter.com/ebeagu_samuel)
- Linkedin: [Ebeagu Samuel](https://www.linkedin.com/in/ebeagusamuel/)

## 🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check the [issues page](issues/).

## Show your support

Kindly give this repository a ⭐️ if you like this project!

## Acknowledgments

- Project specifications by [Microverse](https://www.microverse.org).

- Images downloaded [here](https://generated.photos/).

## 📝 License

This project is licensed under the MIT License.