Project

daredevil

0.0
No commit activity in last 3 years
No release in over 3 years
Daredevil provides insight into JSON API errors with friendly messages, verbose error details, and it's dead simple.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 4.2.8
 Project Readme

Daredevil

This gem provides insight to api errors by providing messages for all general server error response codes. It is inspired by the json_api_responders gem.

Table of contents

  • Status
  • Installation
  • Configuration
  • Usage
  • Developing
  • License
  • Credits

Status

CircleCI

Installation

Add daredevil to your application's Gemfile:

gem 'daredevil'

And then execute:

$ bundle

Inside your base controller, include the module:

module Api
  module V1
    class BaseController < ApplicationController
      include Daredevil
    end
  end
end

Configuration

If you would like to use serializers instead of jbuilder, you can add a config initializer.

Daredevil.configure do |config|
  config.responder_type = :serializers
end

Usage

If a status is not set, the default status will be returned.

class ResourceController
  before_action :set_resource

  def index
    respond_with @resources
  end

  def show
    respond_with @resource
  end

  def create
    if resource.save
      respond_with @resource, status: 201
    else
      respond_with @resource, status: 442
    end
  end

  def update
    if resource.valid?
      respond_with @resource, status: 200
    else
      respond_with @resource, status: 442
    end
  end

  def destroy
    head status: 204
  end

  private

  def set_resource; end
end

If serializers are set as the render method, Daredevil will try to infer which serializer first by checking for a namespaced serializer, then fallback to a non-namespaced serializer.

The following example will look for Api::V1::UserSerializer first, then if not found will look for UserSerializer.

module Api
  module V1
    class UserController
      def index
        respond_with @users
      end
    end
  end
end

Or, specify a serializer specifically:

module Api
  module V1
    class UserController
      def index
        respond_with @users, serializer: KustomUserSerializer
      end
    end
  end
end

Developing

  1. Thank you! We love our contributors!
  2. Clone the repository.
  3. Make your changes in a thoughtfully-named branch.
  4. Ensure 1:1 test coverage.
  5. Submit a Pull Request!
  6. Celebrate! 🎉

License

This project rocks and uses MIT-LICENSE.

Credits

Daredevil is maintained and funded by ProctorU, a simple online proctoring service that allows you to take exams or certification tests at home.