A Grape app mounted on Rack that helps you put together a RESTful API.
- Rack - A minimal, modular, and adaptable interface for developing web applications
- Grape - Aids in creation of REST-like APIs
- Grape-Swagger - Adds swagger compliant documentation to the API
- ActiveRecord - An almost zero-configuration persistence layer
- SQLite3 - An interface with the SQLite3 database engine. For testing purposes.
- Guard - Automatically tests and lints the code whenever file or directories are modified.
- Rubocop - Enforces many of the guidelines outlined in the community Ruby Style Guide.
- RSpec - Provides a behaviour driven development framework
- Shoulda Matchers - RSpec matchers for ActiveRecord
- Factory Girl - A library for setting up Ruby objects as test data.
- Airborne - Aids in the testing of the API
- Database Cleaner - Ensures a clean state for testing.
- and many others
Install the dependencies
$ bundle install
Create and populate the database
$ bundle exec rake db:setup
Start the server
$ rackup
[2018-05-28 15:17:47] INFO WEBrick 1.4.2
[2018-05-28 15:17:47] INFO ruby 2.5.1 (2018-03-29) [x86_64-darwin17]
[2018-05-28 15:17:47] INFO WEBrick::HTTPServer#start: pid=65440 port=9292
The architecture does not depend on the existence of some library of feature laden software. This allows such frameworks to be used as tools, rather than having to cram the system into their limited constraints. The business rules can be tested without the UI, Database, Web Server, or any other external element.
The UI can change easily, without changing the rest of the system. A Web UI could be replaced with a console UI, for example, without changing the business rules.
It is easy to can swap out Sqlite or PostgreSQL, for Mongo, BigTable, CouchDB, or something else. The business rules are not bound to the database.
This is where the web part of the application is stored. It includes all the HTTP related logic such as headers, redirection, status codes, JSON serialization, etc. This layer has no awareness of persistence.
web/[namespace]
- HTTP delivery mechanismweb/[namespace]api.rb
- Api route indexweb/[namespace]app.rb
- Rack/Grape appweb/[namespace]/resource_api.rb
- Rack/Grape app
All business requirements of the application are contained in the lib
folder, in a folder named after the app.
In this example our app is called embryo
, and so is the folder. Examples of business logic:
- Verify user authorization
- Choose data to be displayed
- Determine if additional user input is required
lib/[namespace]
- Root folder for the application business logiclib/[namespace]/models
- Active Record modelslib/[namespace]/operations
- Use cases of the system
Stores and retrieves data to achieve business requirements. Examples:
- Make an API call
- Query a local database
- Access the local filesystem
lib/matchers
- Operation matcherslib/operations
- Operation helperslib/params
- Delivery mechanism helperslib/grape
- Delivery mechanism helpersspec
- Tests
- Run console:
rack-console
- List routes
bundle exec rake routes
- List tasks
bundle exec rake --tasks
- Generate migration file:
bundle exec rake g:migration NAME=migration_name
- All ActiveRecord rake tasks are accessible:
db:migrate
,db:drop
,db:seed
, etc
See LICENSE.