GithubHelp home page GithubHelp logo

octo-woapi / api-with-rails Goto Github PK

View Code? Open in Web Editor NEW
3.0 7.0 0.0 104 KB

🛤Sample API with Ruby on Rails

License: MIT License

Ruby 86.82% JavaScript 1.12% CSS 1.14% HTML 10.92%
rails ruby api api-rest

api-with-rails's Introduction

API with Ruby on Rails

🛤 Sample API with Ruby on Rails, following Katapi contract.

Status

Runnable - You can find a live example here: https://octo-woapi-rails.herokuapp.com/api/v1/products

Getting started

Install rvm

Use the relevant Ruby version

$ rvm use ruby-2.5.7

Install bundler

$ gem install bundler

Install other dependencies

$ bundle

Copy database file and fill it with your database settings

$ cp config/database.yml.example config/database.yml

Create and migrate database

$ rake db:create
$ rake db:migrate
$ rake db:seed

Run the tests

$ rake

Start the project

$ rails s # default port is 3000

Features

You can only GET /products for now, provided you have some in the database. :)

Products

GET /products

[
  {
    "id": 1,
    "name": "Nintendo Switch",
    "price": 300,
    "weight": 3,
    "createdAt": "2018-04-06T13:21:32.611Z",
    "updatedAt": "2018-04-06T13:21:32.611Z"
  }
]

GET /products/1

{
  "id": 1,
  "name": "Nintendo Switch",
  "price": 300,
  "weight": 3,
  "createdAt": "2018-04-06T13:21:32.611Z",
  "updatedAt": "2018-04-06T13:21:32.611Z"
}

POST /products

{
  "name": "Nintendo Switch",
  "price": 300,
  "weight": 3
}

PUT /products/1

{
  "name": "Nintendo Switch",
  "price": 300,
  "weight": 3
}

DELETE /products/1

Orders

GET /orders

[
  {
    "id": 1,
    "shipment_amount": 10,
    "total_amount": 300,
    "weight": 28,
    "status": "pending",
    "products": [
      {
        "id": 2,
        "quantity": 3
      }
    ],
    "createdAt": "2018-04-06T13:21:32.611Z",
    "updatedAt": "2018-04-06T13:21:32.611Z"
  }
]

GET /orders/1

{
  "id": 1,
  "shipment_amount": 10,
  "total_amount": 300,
  "weight": 28,
  "status": "pending",
  "products": [
    {
      "id": 2,
      "quantity": 3
    }
  ],
  "createdAt": "2018-04-06T13:21:32.611Z",
  "updatedAt": "2018-04-06T13:21:32.611Z"
}

POST /orders

{
  "products": [
    {
      "id": 3,
      "quantity": 1
    }
  ]
}

PUT /orders/1

{
  "status": "paid",
  "products": [
    {
      "id": 3,
      "quantity": 1
    }
  ]
}

DELETE /orders/1

Bills

GET /bills

[
  {
    "id": 1,
    "amount": 250,
    "order_id": 3,
    "createdAt": "2018-04-06T13:21:32.611Z",
    "updatedAt": "2018-04-06T13:21:32.611Z"
  }
]

GET /bills/1

{
  "id": 1,
  "amount": 250,
  "order_id": 3,
  "createdAt": "2018-04-06T13:21:32.611Z",
  "updatedAt": "2018-04-06T13:21:32.611Z"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.