An Exercise in Building an API in Rails
Turing School of Software and Design, Module 3
Table of Contents
The purpose of this project is to practice building a practical API application.
Using data related to a mocked e-commerce platform, the goal of this project is to design serializers to format JSON files that can be accessed through a controller.
For a complete breakdown of the project's technical requirements and goals for understanding, please click this link:
Rails Engine Lite
- Fork this Repo (optional), or Clone this Repo with the following command:
- Using https:
git clone https://github.com/ZacHazelwood/Rails-Engine.git
- Using SSH key:
git clone [email protected]:ZacHazelwood/Rails-Engine.git
- Install Required Technologies, or check for correct versions using the following commands:
ruby -v
rails-v
rspec -v
postgres -V
- Install required gems included within the gemfile:
bundle install
- Create PostgreSQL database, run migrations and seed the database:
rails db:{create,migrate,seed}
To access the data presented, simply launch a local server by typing rails s
into the command prompt.
Then, use a browser or PostMan (or equivalent) to explore the API from the following URL and included endpoints, listed below:
http://localhost:3000
If using PostMan, please follow the instructions provided beneath the Postman header from the project details page, Rails Engine Lite
- get all merchants
GET http://localhost:3000/api/v1/merchants
- get one merchant
GET http://localhost:3000/api/v1/merchants/:merchant_id
- get all items held by a given merchant
GET http://localhost:3000/api/v1/merchants/:merchant_id/items
- get all items
GET http://localhost:3000/api/v1/items
- get one item
GET http://localhost:3000/api/v1/items/:item_id
- create an item
POST http://localhost:3000/api/v1/items/:item_id
- edit an item
PUT http://localhost:3000/api/v1/items/:item_id
- delete an item
DESTROY http://localhost:3000/api/v1/items/:item_id
- get the merchant data for a given item ID
GET http://localhost:3000/api/v1/items/:item_id/merchant
- find one merchant by name
GET http://localhost:3000/api/v1/merchants/find?name=some_query
- find all merchants by name
GET http://localhost:3000/api/v1/merchants/find_all?name=some_query
- find one item by name
GET http://localhost:3000/api/v1/items/find?name=some_query
- find all items by name
GET http://localhost:3000/api/v1/items/find_all?name=some_query
- find one item by minimum price
GET http://localhost:3000/api/v1/items/find?min_price=some_query
- find one item by maxmimum price
GET http://localhost:3000/api/v1/items/find?max_price=some_query
- find one item by price range
GET http://localhost:3000/api/v1/items/find?min_price=some_query&max_price=another_query