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
- App
- Curator
- Mapper
- Serializer
- Decorator
- Authorizer
- Affirmation
- Builder
- Testing
App
App
App
Responsibilities
- Grabbing the web request by verb and route
- Creating a default response
- Sending it to the curator
- Serializing the response from the curator to JSON
- Returning the serialized response
Curator
Curator
Curator
Responsibilities
-
Takes a default response and transforms it over a series of functions.
-
Finds/Searches/Builds into the response.collection
-
Validates response.collection
-
Authorizes response.collection
-
Creates/Updates/Deletes into the database
-
Publishes messages to rabbitmq
-
Decorates response.collection
-
Etc...
Mapper
Mapper
Mapper
Responsibilities
-
Maps database row into a ruby object (item)
-
Adds find/search/create/update/delete to the curator
-
"lazy_loads" calculate/derived data into the ruby objects loaded up in response.collection
Serializer
Serializer
Serializer
Responsibilities
-
Converts response into Collection+JSON which includes a base collection and optionally a list of items.
Decorator
Decorator
Decorator
Responsibilities
-
Object-oriented layer of presentation logic like
-
date formats
-
money formats
-
full name
-
Authorizer
Authorizer
Authorizer
Responsibilities
-
Determines which items in a collection the current user can read or write.
Builder
Builder
Builder
Responsibilities
-
Converts params into a template for creating and updating items.
Sections
- App
- Curator
- Mapper
- Serializer
- Decorator
- Authorizer
- Affirmation
- Builder
- Testing
Thank you!
Snapi Section 01 Overview
By Dustin McCraw
Snapi Section 01 Overview
- 1,028