An API designed to power an Ecommerce web application
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
-
Ruby
- The project is built with rubyonrails using ruby version 2.5.3p105, you must install ruby on your local machine first. Please visit the ruby home page to get set up. Please ensure you install the version of ruby noted above.
-
Rails
gem install rails --version 5.2.4.3
-
Postgres database
- Visit the postgresapp homepage and follow their instructions to download the latest version of Postgres.app.
-
Clone the repo
git clone https://github.com/jakejakearell/rails-engine
-
Bundle Install
bundle install
-
Create rails database and migrate
$ rails db:create $ rails db:migrate
-
Start rails server
$ rails s
$ rails bundle exec rspec
The tests are all built using the RSpec and Capybara test suites.
Returns all merchants. Defaults to a max of 20 merchants per page. Can take additional params of page and per_page.
Request: GET http://localhost:3000/api/v1/merchants
Request: GET http://localhost:3000/api/v1/merchants
Response body:
{
"data": [
{
"id": "1",
"type": "merchant",
"attributes": {
"name": "Mike's Awesome Store",
}
},
{
"id": "2",
"type": "merchant",
"attributes": {
"name": "Store of Fate",
}
},
{
"id": "3",
"type": "merchant",
"attributes": {
"name": "This is the limit of my creativity",
}
}
]
}
Returns one merchant if given merchant id
Request: GET http://localhost:3000/api/v1/merchants/:id
Request: GET http://localhost:3000/api/v1/merchant/:id
Response body:
{
"data": {
"id": "1",
"type": "merchant",
"attributes": {
"name": "Schroeder-Jerde"
}
}
}
Returns a merchant's items if given a merchant id
Request: GET http://localhost:3000/api/v1/merchants/:id/items
Request: GET http://localhost:3000/api/v1/merchants/:id/items
Response body:
{
"data": [
{
"id": "16",
"type": "item",
"attributes": {
"name": "Item Adipisci Sint",
"description": "Iure cumque laborum hic autem quidem voluptas. Quis eum adipisci neque magnam. Commodi molestiae exercitationem.",
"unit_price": 229.51,
"merchant_id": 2
}
},
{
"id": "17",
"type": "item",
"attributes": {
"name": "Item Laudantium Ex",
"description": "In dolor architecto doloribus omnis fuga. Dolor minima voluptatem libero voluptatem cum magni ipsam. Et est minus quis doloremque. Praesentium voluptatem dicta eos.",
"unit_price": 607.13,
"merchant_id": 2
}
},
ect....
]
}
Returns a item if given a item id
Request: GET http://localhost:3000/api/v1/items/:id/
Request: GET http://localhost:3000/api/v1/items/:id/
Response body:
{
"data": {
"id": "16",
"type": "item",
"attributes": {
"name": "Widget",
"description": "High quality widget",
"unit_price": 100.99,
"merchant_id": 14
}
}
}
Updates an item. Must include name, description, unit price and merchant_id in request body
Request: PUT http://localhost:3000/api/v1/items/:id
Request: PUT http://localhost:3000/api/v1/items/16
Request body:
{
"name": "value1",
"description": "value2",
"unit_price": 100.99,
"merchant_id": 14
}
Response body:
{
"data": {
"id": "16",
"type": "item",
"attributes": {
"name": "value1",
"description": "value2",
"unit_price": 100.99,
"merchant_id": 14
}
}
}
Creates an item. Must include name, description, unit price and merchant_id in request body
Request: POST http://localhost:3000/api/v1/items/
Request: POST http://localhost:3000/api/v1/items/
Request body:
{
"name": "value3",
"description": "value4",
"unit_price": 100.99,
"merchant_id": 14
}
Response body:
{
"data": {
"id": "17",
"type": "item",
"attributes": {
"name": "value3",
"description": "value4",
"unit_price": 100.99,
"merchant_id": 14
}
}
}
Returns a item if given a item id
Request: GET http://localhost:3000/api/v1/items/:id/
Request: GET http://localhost:3000/api/v1/items/:id/
Response body:
{
"data": {
"id": "16",
"type": "item",
"attributes": {
"name": "Widget",
"description": "High quality widget",
"unit_price": 100.99,
"merchant_id": 14
}
}
}
-- Billie Thompson - Provided README Template - PurpleBooth