Opinionated template Sinatra app for writing excellent APIs in Ruby.
It bundles some of the patterns we like to develop these apps:
- Config:
ENVwrapper for explicit defining what config vars are mandatory and optional - Endpoints: the Sinatra equivalent of a Rails Controller
- Initializers: tiny files to configure libraries/etc (equivalent of Rails)
- Mediators: plain ruby classes to manipulate models
- Models: very thin wrappers around the database
And gems/helpers to tie these together and support operations:
- CORS middleware to allow JS developers to consume your API
- Honeybadger for tracking exceptions
- Log helper that logs in data format to stdout
- Rspec for lean and fast testing
- Puma as the web server, configured for optimal performance on Heroku
- Rack-test to test the API endpoints
- Request IDs
- RequestStore, thread safe option to store data with the current request
- RR for amazing mocks and stubs
- Sequel for ORM
- Sequel-PG because we don't like mysql
- Versioning to allow versioning your API in the HTTP Accept header
First make sure the following is installed:
Then install the gem:
$ gem install plinyAnd initialize a new app:
$ pliny-new myapp
$ cd myapp && bin/setupPliny also bundles some generators to help you get started:
$ bundle exec pliny-generate model artist
created model file ./lib/models/artist.rb
created migration ./db/migrate/1395873224_create_artist.rb
created test ./test/models/artist_test.rb
$ bundle exec pliny-generate mediator artists/creator
created base mediator ./lib/mediators/base.rb
created mediator file ./lib/mediators/artists/creator.rb
created test ./test/mediators/artists/creator_test.rb
$ bundle exec pliny-generate endpoint artists
created endpoint file ./lib/endpoints/artists.rb
add the following to lib/routes.rb:
mount Endpoints::Artists
created test ./spec/endpoints/artists_spec.rb
created test ./spec/acceptance/artists_spec.rb
$ bundle exec pliny-generate migration fix_something
created migration ./db/migrate/1395873228_fix_something.rb
$ bundle exec pliny-generate schema artists
created schema file ./docs/schema/schemata/artist.yaml
rebuilt ./docs/schema.jsonTo test your application:
bundle exec rakeOr to run a single test suite:
bundle exec rspec spec/acceptance/artists_spec.rbRun tests:
bundle install
git submodule update --init
rake
Created by Brandur Leach and Pedro Belo.