Skip to content

xevix/grape-oink

Repository files navigation

Overview

The grape-oink gem provides a way to use the Oink library with Grape.

Requirements

  • Grape >= 0.10.0

Usage

Build and Install

To use, just install the gem from RubyGems or via Bundler by requiring it in your Gemfile.

gem 'grape-oink'

Middleware Setup

In your Grape API, install the middleware which will translate Grape endpoints to what Oink expects.

use Grape::Middleware::OinkMiddleware

Set up the Oink middleware. The below example is in config.ru of a generic Rack project.

require 'oink'
oink_path = File.expand_path('../log/oink.log', __FILE__)
use Oink::Middleware, :logger => Hodel3000CompliantLogger.new(oink_path)

Endpoint translation

Oink expects Rails-style endpoints where there is a controller and an action. Grape is more flexible than Oink in what these can be, so a few translation rules were added to make Oink happy.

The controller name might be namespaced. In this case, only the last class will be used in snakecase. This may change later.

My::Name::Space::UserObjects --> 'user_objects'

Certain tokens in the action are replaced.

Token Replacement
':' 'col_'
'/' 'sl_'

An example of a translation would be:

/:id --> sl_col_id

TODO

  • Include endpoint method in the action name. Oink doesn't seem to support method out of the box.

About

A middleware for Grape to allow working with Oink

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages