Giter Site home page Giter Site logo

ol's Introduction

OL - OwnLocal

Build Status

Simple Rails API app for the interview project at OwnLocal. The data.csv has been provided by OwnLocal.

This rails-api app uses Active Model Serializers (AMS) & Kaminari to serialize & paginate the businesses data in JSON format. There are different kind of adapters that you can use with AMS. For this project the adapter is set to JSON since it has the closet format to the provided example:

curl -H "accept: application/vnd.ol+json; version=1" http://localhost:3000/businesses/1

{
  "businesses": [{
    "id": 1,
    "name": "...",
  }, ],
}

You can set the AMS adapter at config/initializers/ams.rb. For example you can change it to json_api which provide pagination links as well as metadata. rails-api suggest to use json_api, and you can read more about it here

Setup

# Install required gems from Gemfile
bundle install

# Create & seed the database
rake db:setup

# Start the rails server
rails s

Test

The tests has been written in rspec and you can find the request tests at spec/requests/businesses_spec.rb.

# Setup test db
rake db:setup test

# Run all specs
rspec spec/

Routes

The routes that provided by this api.

Please note the JSON example are not complete, and it is just used for demonstration purposes

GET /businesses

By default this route will provide you the first 50 business objects including the pagination meta data:

{
  "businesses":[{
    "id":0,
    "uuid":"123",
    "name":"xyz",
  }, ],
  "meta":{
    "current_page":1,
    "next_page":2,
    "prev_page":null,
    "total_pages":1000,
    "total_count":50000
  }
}

GET /businesses?page=2&per_page=20

You can also customize the page and per_page in query parameters.

page: the page number

per_page: the number of business(es) items you want to have in a page

GET /businesses/:id

This route will return an individual business item.

{
  "business":{
    "id":0,
    "uuid":"123",
    "name":"xyz",
  }
}

Note if the item with the provided id doesn't exist then the response include the 404 error code and an error message (Couldn't find Business with 'id'=:id)

ol's People

Contributors

ardeshirj avatar

Watchers

 avatar  avatar

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.