Fern is a DSL for writing REST APIs on top of Ruby on Rails.
Fern-API provides a simple DSL for defining API endpoints.
Fern provides methods for
The basic structure of a request looks like this:
Fern-Parameters provides basic query string parameter validation for a variety of common data types.
Request parameters are defined in a
While the raw params can still be accessed inside of your request block via the
params variable, when declaring a
params block for an endpoint, you should use
For example, for the above endpoint, you could access the
The following param types are supported:
param method also accepts a number of optional arguments:
Fern-Documentation is an experimental utility for automatically generating documentation from your Fern API.
Fern-Documentation provides the
doc DSL method for specifying a documentation string for an endpoint.
Documentation can be generated by the
fern:docs Rake task. The documentation will be output as markdown files in the
Forms are classes which accept a params hash as an argument to their constructor.
Fern-Form provides the
form DSL method for declaring the form for an endpoint. The form will be instantiated automatically using the params hash from the action and can be accessed via
Presenters are classes which satisfy two criteria:
- They accept a model instance as an argument to their constructor.
- They implement an
Fern-Presenter provides a
presenter DSL method to declare a presenter for an endpoint, and a
present DSL method to instantiate that presenter, call
as_json, and automatically return the result.
present DSL method also accepts enumerables, in which case it will instantiate the presenter once for each element in the array.