Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.
/ grape-embryo Public archive

A Grape app mounted on Rack that helps you put together a RESTful API. Lightweight and doesn't lock you in a framework.

License

Notifications You must be signed in to change notification settings

wilsonsilva/grape-embryo

Repository files navigation

Grape Embryo

Build Status Code Climate Test Coverage Security No monkey-patches MIT license

A Grape app mounted on Rack that helps you put together a RESTful API.

Built With

  • 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

Getting Started

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

Architecture

Goals

Independent of Frameworks

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.

Independent of UI

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.

Independent of Database

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.

Organizational layers

Delivery

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 mechanism
  • web/[namespace]api.rb - Api route index
  • web/[namespace]app.rb - Rack/Grape app
  • web/[namespace]/resource_api.rb - Rack/Grape app

Business Logic

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 logic
  • lib/[namespace]/models - Active Record models
  • lib/[namespace]/operations - Use cases of the system

Persistence Logic

Stores and retrieves data to achieve business requirements. Examples:

  • Make an API call
  • Query a local database
  • Access the local filesystem

Utilities

  • lib/matchers - Operation matchers
  • lib/operations - Operation helpers
  • lib/params - Delivery mechanism helpers
  • lib/grape - Delivery mechanism helpers
  • spec - Tests

Development

  • 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

License

See LICENSE.

About

A Grape app mounted on Rack that helps you put together a RESTful API. Lightweight and doesn't lock you in a framework.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages