Code Monkey home page Code Monkey logo

grape_api_example's Introduction

Sample Ruby API

Sample Objectives

You will be creating a simple user management API using the tools described below.

Create API endpoints that enable the following:

  1. Albums creating and deleting albums changing album details (name, artist, album art) adding / removing songs Artists (musicians/bands) creating and deleting artists changing artist details (name, bio, albums)
  2. Songs creating and deleting songs changing song details (name, duration, genre, album, artist, etc) songs can be featured and featured songs have a here image and extra texts to describe or promote it
  3. Playlists creating and deleting playlists changing playlist name adding / removing songs from playlist

The API should be written in Ruby Rails and/or an API framework such as Grape The information should be stored in a database of your choice

Installation Process:

  1. Install RVM (https://rvm.io/rvm/install)
  2. Run rvm install 2.3.3
  3. Run gem install bundler
  4. Clone repository
  5. cd api-test
  6. Run bundle install
  7. Duplicate .env.development.sample file and rename to .env.development
  8. Enter correct env values for .env.development
  9. Repeat steps 7 and 8 for env.test
  10. To start ruby server, run make run

Note: Be sure to set database url for env.test to your test database and not your development database. Tests will truncate all tables in the test database before running!

Libraries

Routing

Grape: https://github.com/ruby-grape/grape

Grape Entity: https://github.com/ruby-grape/grape-entity

Grape Swagger: https://github.com/ruby-grape/grape-swagger

Database / Models

Sequel: http://sequel.jeremyevans.net/

Forms

Hanami: https://github.com/hanami/validations

Uses dry validation as the syntax to validate inputs. Suggested reading: http://dry-rb.org/gems/dry-validation/

Testing

Rspec: http://www.relishapp.com/rspec/rspec-core/docs

Factory Girl: https://github.com/thoughtbot/factory_girl

Faker: https://github.com/stympy/faker

Migrations

To create a migration: bundle exec rake "db:migration[my_migration]"

To code the migration: go to application/migrate/XXXXXX_my_migration.rb -- instructions here: https://github.com/jeremyevans/sequel/blob/master/doc/migration.rdoc

To apply the migration: bundle exec rake db:migrate

To apply the migration to your test database: RACK_ENV=test bundle exec rake db:migrate

Running Tests

Run your tests using:

update DATABASE_URL in env.test

createdb sample_test

RACK_ENV=test rake db:migrate

bundle exec rake spec

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.