Snapi

Section 1

Overview

Snapi/Apiv3

  • Snapi is a Ruby api built on top of Sinatra.
  • It takes a web request and over a series of functions it transforms the data into a json response.
  • It's a home grown api using a functional approach.
  • It returns collection+json.

Sections

  1. App
  2. Curator
  3. Mapper
  4. Serializer
  5. Decorator
  6. Authorizer
  7. Affirmation
  8. Builder
  9. Testing

App

App

App

Responsibilities

  1. Grabbing the web request by verb and route
  2. Creating a default response
  3. Sending it to the curator
  4. Serializing the response from the curator to JSON
  5. Returning the serialized response

Curator

Curator

Curator

Responsibilities

  1. Takes a default response and transforms it over a series of functions.

  2. Finds/Searches/Builds into the response.collection

  3. Validates response.collection

  4. Authorizes response.collection

  5. Creates/Updates/Deletes into the database

  6. Publishes messages to rabbitmq

  7. Decorates response.collection

  8. Etc...

Mapper

Mapper

Mapper

Responsibilities

  1. Maps database row into a ruby object (item)

  2. Adds find/search/create/update/delete to the curator

  3. "lazy_loads" calculate/derived data into the ruby objects loaded up in response.collection

Serializer

Serializer

Serializer

Responsibilities

  1. Converts response into Collection+JSON which includes a base collection and optionally a list of items.

Decorator

Decorator

Decorator

Responsibilities

  1. Object-oriented layer of presentation logic like

    1. ​date formats

    2. money formats

    3. full name

Authorizer

Authorizer

Authorizer

Responsibilities

  1. Determines which items in a collection the current user can read or write.

Builder

Builder

Builder

Responsibilities

  1. Converts params into a template for creating and updating items.

Sections

  1. App
  2. Curator
  3. Mapper
  4. Serializer
  5. Decorator
  6. Authorizer
  7. Affirmation
  8. Builder
  9. Testing

Thank you!

Snapi Section 01 Overview

By Dustin McCraw

Snapi Section 01 Overview

  • 1,028