https://github.com/ianmurrays/rails_api_base
This is a personal Rails 4 base project for APIs. Includes versioning and simple authentication.
https://github.com/ianmurrays/rails_api_base
Last synced: 6 months ago
JSON representation
This is a personal Rails 4 base project for APIs. Includes versioning and simple authentication.
- Host: GitHub
- URL: https://github.com/ianmurrays/rails_api_base
- Owner: ianmurrays
- Created: 2014-06-12T02:46:42.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-06-12T03:03:49.000Z (over 11 years ago)
- Last Synced: 2025-06-09T00:38:55.194Z (7 months ago)
- Language: Ruby
- Size: 148 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rails API Base
This is a simple base for a Rails API server. It uses [versionist](https://github.com/bploetz/versionist) to version the API, and includes a simple User model with authentication.
## How does authentication work?
The user model `has_many` authentication tokens that have (or don't have) expiration dates. Each time a client wants an authentication token, they have to POST to /v1/authenticate:
$ curl -X POST -d '{"email": "email@example.org", "password": "123"}' -H "Content-Type: application/json" http://localhost:3000/v1/authenticate
{"token":"bfe6e14b-5bac-4cb9-8f92-436b475221e9","expires_at":"2014-06-13T02:25:28.753Z"}
In order to access protected resources, clients have to send a header with a valid token:
$ curl -X GET -H "Authorization: bfe6e14b-5bac-4cb9-8f92-436b475221e9" -H "Content-Type: application/json" -i http://localhost:3000/v1/protected/path
That's it!
## Want to contribute?
1. Fork
2. Create a branch
3. Create a pull request