Giter VIP home page Giter VIP logo

small-rails's Introduction

Small - Rails API

This is a sample project used to illustrate the Flux architecture with React. Checkout the full article here

Setup

bundle install
rake db:create
rake db:migrate
rake db:seed
rails s

Consuming the API

Signup - users#create

curl -X POST -H "Content-Type: application/json" -d '{"user": {"username": "testuser", "email": "[email protected]", "password": "12341234", "password_confirmation": "12341234"}}' http://localhost:3000/v1/users

>> {"email":"[email protected]","username":"testuser","token_type":"Bearer","user_id":12,"access_token":"12:cccyXLZ7o_XpK6MxU_Bt"}

Login - sessions#create

curl -X POST -H "Content-Type: application/json" -d '{"email": "[email protected]", "password": "12341234"}' http://localhost:3000/v1/login

>> {"email":"[email protected]","username":"testuser","token_type":"Bearer","user_id":12,"access_token":"12:cccyXLZ7o_XpK6MxU_Bt"}

Create Story - stories#create

curl -X POST -H "Content-type: application/json" -H "Authorization: 12:cccyXLZ7o_XpK6MxU_Bt" -d '{ "story": { "title": "Test Title", "body": "blah blah blah blah blah blah blah" } }' http://localhost:3000/v1/stories

>> {"story":{"title":"Test Title","body":"blah blah blah blah blah blah blah","created_at":"2015-08-20T19:43:07.701Z","abstract":"blah blah blah blah blah blah blah","id":11,"user":{"username":"testuser"}}}

Show Story - stories#show

curl -X GET -H "Content-type: application/json" -H "Authorization: 12:cccyXLZ7o_XpK6MxU_Bt" http://localhost:3000/v1/stories/11

>> {"story":{"title":"Test Title","body":"blah blah blah blah blah blah blah","created_at":"2015-08-20T19:43:07.701Z","abstract":"blah blah blah blah blah blah blah","id":11,"user":{"username":"testuser"}}}

All Stories - stories#index

curl -X GET -H "Content-type: application/json" -H "Authorization: 12:cccyXLZ7o_XpK6MxU_Bt" http://localhost:3000/v1/stories/

>> {"stories":[{"title":"Test Title","created_at":"2015-08-20T19:43:07.701Z","abstract":"blah blah blah blah blah blah blah","id":11,"user":{"username":"testuser"}},{"title":"Direct Communications Manager","created_at":"2015-08-20T17:43:14.845Z","abstract":"Dignissimos quidem voluptas beatae voluptatibus. Nihil dolorem eveniet maxime. Ex aut sapiente laborum vel temporibus tempora nobis. Qui magnam repudiandae ut et. Et minus quia dolorum illo esse. Ut ad","id":10,"user":{"username":"gino_huel"}},{"title":"Senior Creative Assistant","created_at":"2015-08-20T17:43:14.840Z","abstract":"Consequuntur enim nulla. Velit nihil ipsum voluptates nulla aperiam commodi qui. Voluptatem in enim. Placeat voluptate sed et culpa non molestias. Ut et nihil aut iure exercitationem. Ut laborum quia r","id":9,"user":{"username":"ali.keler"}},{"title":"National Interactions Executive","created_at":"2015-08-20T17:43:14.837Z","abstract":"Impedit voluptatem reiciendis est provident quia aut fugit. Officia enim voluptas dignissimos tempora inventore quia possimus. Perferendis eos enim veritatis aspernatur ut. Sed placeat nihil. Suscipit ","id":8,"user":{"username":"ethel.weimann"}},{"title":"Senior Branding Developer","created_at":"2015-08-20T17:43:14.832Z","abstract":"Ut consequatur et ex fuga. Cumque dicta rem vel numquam tempora voluptas ut. Molestiae voluptas qui minima non. Laborum voluptatem consequatur velit sed. Eum eos id. Eum aliquid et iusto non. Asperiore","id":7,"user":{"username":"ali.keler"}},{"title":"Dynamic Metrics Engineer","created_at":"2015-08-20T17:43:14.828Z","abstract":"Ut dignissimos modi aut non. Eaque excepturi ipsa eligendi. Pariatur dolor cupiditate. Libero tenetur hic labore esse. Est amet praesentium quia corporis. Consequatur illum numquam similique deleniti r","id":6,"user":{"username":"ali.keler"}},{"title":"National Branding Specialist","created_at":"2015-08-20T17:43:14.824Z","abstract":"Porro omnis beatae. Omnis magnam quae. Iusto molestias cupiditate architecto consequuntur aut. Saepe placeat in odit eum quaerat commodi molestiae. Modi adipisci corrupti dolores sit vel atque. Magni m","id":5,"user":{"username":"margaretta"}},{"title":"National Interactions Technician","created_at":"2015-08-20T17:43:14.820Z","abstract":"Ipsum nesciunt id autem quas quaerat eum et. Ipsa non est fugiat adipisci. Suscipit facere explicabo consequatur. Eos ducimus corrupti. Ut voluptates nemo veritatis beatae sint. Ratione at quasi eos ma","id":4,"user":{"username":"ethel.weimann"}},{"title":"Internal Intranet Producer","created_at":"2015-08-20T17:43:14.816Z","abstract":"Dolor dolorum omnis eum maxime. Aut necessitatibus aut aspernatur. Nesciunt et provident laudantium explicabo expedita voluptatem distinctio. Iste aperiam veniam veritatis ex incidunt voluptas quisquam","id":3,"user":{"username":"abdullah"}},{"title":"Human Data Engineer","created_at":"2015-08-20T17:43:14.810Z","abstract":"Sapiente architecto unde explicabo sit tempora. Est quia eveniet cumque. Pariatur aut cupiditate qui. Dolor vitae harum eum quia voluptatum consequuntur omnis. Tenetur quasi et. A ut dolores. Amet reru","id":2,"user":{"username":"dawn"}},{"title":"International Optimization Technician","created_at":"2015-08-20T17:43:14.805Z","abstract":"Totam vitae harum reiciendis iste quod. Eum sapiente dolore consequatur et quod molestiae. A laboriosam rem et. Odio rerum perspiciatis quia architecto illum. Et eos eaque nemo. Voluptas eaque voluptat","id":1,"user":{"username":"daphnee"}}]}

MIT License

Copyright (c) 2015 Fancy Pixel. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

small-rails's People

Contributors

abundnce10 avatar andreamazz avatar bryant1410 avatar freeslugs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

small-rails's Issues

Missing config/database.yml

rake db:create spits out an error about a missing config/database.yml.

I notice it was ignored in your .gitignore, adding a this file worked for me. This is all new to me, but I hope this helps.

config/database.yml

development:
adapter: sqlite3
database: db/development.sqlite3

Trouble consuming API

I cloned this repository and followed the commands in the README file. However, when I go to make curl commands to create a user I'm having trouble. Can you add example curl commands to the README so that people new to the repo know how to consume the API?

I ran rake routes and found a POST to v1/users(.:format) would hit the users#create method. So, I try this command: curl -X POST -H "Content-Type: application/json" -d '{"username": "testuser", "email": "[email protected]", "password": "123412324", "password_confirmation": "123412234"}' http://localhost:3000/v1/users but see in my Rails server that I get this error:

Started POST "/v1/users" for 127.0.0.1 at 2015-08-20 11:00:58 -0700
Processing by V1::UsersController#create as JSON
  Parameters: {"username"=>"testuser", "email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}
Completed 400 Bad Request in 1ms

ActionController::ParameterMissing (param is missing or the value is empty: user):
  app/controllers/v1/users_controller.rb:20:in `user_params'
  app/controllers/v1/users_controller.rb:8:in `create'

So, I then tried this command: curl -X POST -H "Content-Type: application/json" -d '{ "user": {"username": "testuser", "email": "[email protected]", "password": "123412324", "password_confirmation": "123412234"} }' http://localhost:3000/v1/users

And this was returned:: {"error":"translation missing: en.user_create_error"}.

If I look in my Rails server I see this:

Started POST "/v1/users" for 127.0.0.1 at 2015-08-20 11:08:09 -0700
Processing by V1::UsersController#create as JSON
  Parameters: {"user"=>{"username"=>"testuser", "email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}}
   (0.1ms)  begin transaction
  User Exists (0.1ms)  SELECT  1 AS one FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
   (0.0ms)  rollback transaction
Completed 422 Unprocessable Entity in 66ms (Views: 0.1ms | ActiveRecord: 0.2ms)

So, any help on the default way to setup requests to the API would be much appreciated!

If you just want to comment here how to do it I can make the necessary Pull Request. Thanks!

Create Session

I'm getting Completed 422 Unprocessable Entity when I copy/paste the curl for sessions#create. I have not altered any code. Creating the user worked, but I cannot use cURL or Postman to create the session. Any idea?

The error returned by json is:
{
"error": "translation missing: en.sessions_controller.invalid_login_attempt"
}

I noticed that the curl url is http://localhost:3000/v1/users, I've tried login instead of users, and it still errors.

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.