In this project, we're set up a simple Rails API-only-application. Rails API-only-applications are slimmed down compared to traditional Rails web applications.
Test Driven Development of a RESTful JSON API With Rails
- Ruby v2.7.2
- Ruby on Rails v6.0.3.2
- RSpec-Rails for testing
The API will expose the following RESTful endpoints.
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.
Ruby: 2.6.5 Rails: 6.0.3.2 Postgres: >=9.5
$ git clone https://github.com/acushlakoncept/books-api-article-part1.git
$ cd books-api-article-part1
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
Start server with:
rails server
Open http://localhost:3000/
in your browser.
Deploying to a live server like Heroku is easy, make sure you have the necessary credentials setup on your local machine
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
heroku run rails db:migrate
heroku run rails db:seed
heroku open
Enjoy your newly deployed rails API
rpsec
๐ค Uduak Essien
- Github: @acushlakoncept
- Twitter: @acushlakoncept
- Linkedin: acushlakoncept
Contributions, issues and feature requests are welcome!
Feel free to check the issues page.
Give a โญ๏ธ if you like this project!