Giter VIP home page Giter VIP logo

api_exercise's Introduction

API Exercise

Here's the solution for the suggested exercise using Rails 5 to build a tiny API.

The main difference between this solution and the description provided is that I'm modeling GroupEvent here intended to be a Group with many events on it and an additional User entity was introduced to reflect what I think that should be something more close to a tiny but useful first version.

Here's how the models relationship looks like:

==============           ==============           ==============
|            |           |            |           |            |
|    User    |  1 => N   | GroupEvent |  1 => N   |    Event   |
|            |           |            |           |            |
==============           ==============           ==============

Additionally, instead of Rspec the tests was intentionally written using the Minitest (included by default on Rails 5) and all test can be found in the /test folder.

Questions or feedbacks about this solution are very welcome at any time.

Regards, Tailor Fontela.

Setup and general instructions

Ruby version

2.4.0

Rails version

5.0.0.1

Initial Setup

bundle install

rake db:setup

Running the test suite

rake test

Examples to use the API

Users

Creating a new User

  curl -d "user[name]=Lucas"  http://localhost:3000/users

Showing an User

  curl http://localhost:3000/users/#{user_id}

Listing all Users

curl http://localhost:3000/users/

Group Event

Creating a Group Event

curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d ' {"group_event":{"title":"Canada Trip","days_duration":"20", "user_id":"1"}}' http://localhost:3000/group_events

Listing all Group Events

curl http://localhost:3000/group_events

Showing a Group Events

  curl http://localhost:3000/group_events/#{group_event_id}

Updating a Group Events

curl -H "Accept: application/json" -H "Content-type: application/json" -d '{"group_event":{"title":"Brazil Trip"}}' -X PATCH http://localhost:3000/group_events/#{group_event_id}

Event

Creating an Event

curl -H "Accept: application/json" -H "Content-type: application/json" -d ' {"event":{"name":"Passport","description":"renew the passport", "location":"São Paulo", "start_date":"10-10-2016", "end_date":"12-10-2016", "group_event_id": "1"}}' http://localhost:3000/events

Showing an Event

  curl http://localhost:3000/events/#{event_id}

Showing all Events

  curl http://localhost:3000/events/

Updating an Event

curl -H "Accept: application/json" -H "Content-type: application/json" -d '{"event":{"name":"bubble fish"}}' -X PATCH http://localhost:3000/events/#{event_id}

Deleting an Event

curl -X DELETE http://localhost:3000/events/#{event_id}

api_exercise's People

Contributors

taylorrf avatar

Watchers

James Cloos avatar Mohan 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.