0.0
No commit activity in last 3 years
No release in over 3 years
An implementation of draft-nottingham-http-problem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0

Runtime

 Project Readme

ApiProblem for Rails

Code Climate Build Status Coverage Status

Builds a structure for your Rails application to handle application/api-problem+json and application/api-problem+xml. (http://tools.ietf.org/html/draft-nottingham-http-problem-06). To read more about the media type (http://www.mnot.net/blog/2013/05/15/http_problem)

Installation

Add this line to your application's Gemfile:

gem 'api_problem'

And then execute:

$ bundle

Or install it yourself as:

$ gem install api_problem

Usage in Rails

ApiProblem provides a Railtie that registers the proper MIME types with Rails:

  • application/api-problem+json
  • application/api-problem+xml

This gem also installs a generator for your project

rail g api_problem bad_token_error

You can specify the problem detail object members

rail g api_problem bad_token_error type:"http://example.com/probs/out-of-credit" status:403 title:"You do not have enough credit." detail:"Your current balance is 30, but that costs 50."

You can also namespace it with the ns key

rail g api_problem bad_token_error ns:api

About the type, if you DON'T want a type you need to specify with false

rail g api_problem bad_token_error type:false

About the type, if you dont set a type, it will default to the error name

# This will create a bad_token_error type for you.
rail g api_problem bad_token_error

Files that get created for you

create app/views/api_problems/bad_token_error.jbuilder
create app/views/api_problems/bad_token_error.xml.erb
create app/views/errors/bad_token_error.html.erb
create app/controllers/errors_controller.rb
route  match '/bad_token_error' => 'errors#bad_token_error', :via => :get, :as => :bad_token_error

TODO

  • Tests for the generator :)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request