Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/acushlakoncept/books-api-article-part3


https://github.com/acushlakoncept/books-api-article-part3

Last synced: 5 days ago
JSON representation

Awesome Lists containing this project

README

        

# How to Build a RESTful API Authentication With JWT (TDD Approach)

In this part of the project we we'll focus on the login, register endpoints, and securing our book's endpoint using JWT.

## Article
[How to Build a RESTful API Authentication With JWT (TDD Approach)](https://www.microverse.org/blog/build-a-restful-api-authentication-with-jwt)

## Built With

- Ruby v2.7.2
- Ruby on Rails v6.0.3.2
- RSpec-Rails for testing

## Current API Endpoints

The API will expose the following RESTful endpoints.
### BaseUrl: {Host-URL}/api/v1

| Endpoint | Functionality |
|-------------------------|------------------------------|
| POST /register | Signup |
| POST /login | Login |
| GET /books | Get all books |
| GET /books/:id | Get a bppl |
| POST /books | Add a new book |
| DELETE /books/:id | Delete a book |
| PUT /books/:id | Update a book |
| POST /categories | Add category |
| GET /categories | Get categories |

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

### Prerequisites

Ruby: 2.6.5
Rails: 6.0.3.2
Postgres: >=9.5

### Setup

~~~bash
$ git clone https://github.com/acushlakoncept/books-api-article-part3.git
$ cd books-api-article-part3
~~~

Install gems with:

```
bundle install
```

Setup database with:

> make sure you have postgress sql installed and running on your system

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

### Usage

Start server with:

```
rails server
```

Open `http://localhost:3000/` in your browser.

### Deploy to a live server

Deploying to a live server like Heroku is easy, make sure you have the necessary credentials setup on your local machine

```bash
heroku create
heroku rename app-new-name
git push heroku $BRANCH_NAME:master
```
if you are already in master branch no need to add $BRANCH_NAME, just use `git push heroku master`

```bash
heroku run rails db:migrate
heroku run rails db:seed
heroku open
```

Enjoy your newly deployed rails API

### Run tests

```
rpsec
```

# Authors

👤 **Uduak Essien**

- Github: [@acushlakoncept](https://github.com/acushlakoncept/)
- Twitter: [@acushlakoncept](https://twitter.com/acushlakoncept)
- Linkedin: [acushlakoncept](https://www.linkedin.com/in/acushlakoncept/)

## 🤝 Contributing

Contributions, issues and feature requests are welcome!

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

## Show your support

Give a ⭐️ if you like this project!

## Acknowledgement
[Microverse Inc](https://www.microverse.org/)