RailsLocationHeader
RailsLocationHeader is a Rails gem that automatically adds X-Entity-ID and Location headers when a new record is successfully created in a create action. This helps in providing additional metadata about the created resource in API responses.
Installation
Add this gem to your application's Gemfile by executing:
bundle add rails_location_headerIf bundler is not being used to manage dependencies, install the gem by executing:
gem install rails_location_headerUsage
To use this gem, include it in your Rails application. The gem automatically integrates with Rails controllers via a Railtie and works out of the box.
How It Works
- 
createaction with a 201 status: Thecreateaction must return an HTTP201 Createdstatus.
- 
Instance variable: Declare an instance variable in the createaction that matches the entity name (e.g.,@postinPostsController).
- 
showaction and route: Ensure the controller has ashowaction and a corresponding route to construct the resource's URL.
Headers Added
When the above requirements are met, the gem automatically adds the following headers to the response:
- 
X-Entity-ID: The ID of the created resource.
- 
Location: The URL of the created resource.
No additional configuration is needed.
Development
After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run:
bundle exec rake installTo release a new version, update the version number in lib/rails_location_header/version.rb, and then run:
bundle exec rake releaseThis will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/EliSebastian/rails_location_header. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the RailsLocationHeader project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the code of conduct.