https://github.com/omkz/rails-both-web-api-example
Building a RESTful API with Rails 5 for web and mobile application
https://github.com/omkz/rails-both-web-api-example
api rails restful restful-api ruby rubyonrails
Last synced: about 2 months ago
JSON representation
Building a RESTful API with Rails 5 for web and mobile application
- Host: GitHub
- URL: https://github.com/omkz/rails-both-web-api-example
- Owner: omkz
- Created: 2016-10-31T05:51:47.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-27T19:36:53.000Z (over 9 years ago)
- Last Synced: 2025-03-05T03:15:50.374Z (over 1 year ago)
- Topics: api, rails, restful, restful-api, ruby, rubyonrails
- Language: Ruby
- Homepage:
- Size: 34.2 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# how to use this app
#### migrate the database:
`
➜ rails db:migrate
`
#### create Base64 encoded string of this user’s username and password. Open up your rails console and type in the following (see db/seeds.rb, I have inserted data into the database there)
`
irb(main):001:0> Base64.encode64("omz@gmail.com:rahasia")
`
return:
=> "b216QGdtYWlsLmNvbTpyYWhhc2lh\n"
#### run our initial request to get a valid token with cURL:
`
➜ curl http://localhost:3000/token -H 'Authorization: Basic b216QGdtYWlsLmNvbTpyYWhhc2lh\n' `
the output:
{"token":"6980f982ab9fef7171999600187427fd"}%
#### submit request with token and get data:
`
➜ curl http://localhost:3000/api/v1/posts/1 -H 'Authorization: Token token=6980f982ab9fef7171999600187427fd'
`
the output:
{"id":1,"title":"First Post","body":"An Airplane","created_at":"2017-01-27T18:47:56.923Z","comments":[]}%