-
The request enters the server: https://github.com/brandfolder/jsonapionify/blob/master/lib/jsonapionify/api/server.rb#L15-L17
-
The resouce and id (if present) are identified and used to lookup a resource. https://github.com/brandfolder/jsonapionify/blob/master/lib/jsonapionify/api/server.rb#L31-L41
-
The resource is found by its name. Resource definitions are not converted to classes until they are called the first time. When defining a resource you are actually just defining a block that is eventually passed to Class.new(parent, &resource block) https://github.com/brandfolder/jsonapionify/blob/master/lib/jsonapionify/api/base/resource_definitions.rb#L11-L23
-
process
is called on the resource. Here we determine if an action on the main resource can fufill the request or if the request belongs to a relationship. The relationship lookup just includes an extra step to locate the relationship. https://github.com/brandfolder/jsonapionify/blob/master/lib/jsonapionify/api/resource/definitions/actions.rb#L87-L95Actions are prefined mappings that the user defines on the resource as methods. They are
list
,create
,read
,update
,delete
. Additionally the actionsshow
,add
,remove
are available on relationships. -
Once
process
locates an action it callsnew
on the resource. This sets up all the necessary context made available to the request. https://github.com/brandfolder/jsonapionify/blob/master/lib/jsonapionify/api/action.rb#L97-L105 https://github.com/brandfolder/jsonapionify/blob/master/lib/jsonapionify/api/resource.rb#L38-L62Contexts are defined as blocks and only invoked on first invocation, This is to prevent from invalid contexts from being called and to reduce the number of method calls.
-
call
is invoked on the resource. The result of which calls the commit block of the action. For example:create do |context| # create the resource end
-
Once the commit block is run, the response is processed. This is done by using a series of builders. https://github.com/brandfolder/jsonapionify/blob/master/lib/jsonapionify/api/resource/builders.rb https://github.com/brandfolder/jsonapionify/blob/master/lib/jsonapionify/api/resource/builders/resource_builder.rb
-
Once this is complete,
Oj
builds the JSON object and sends it to the client.
Created
June 17, 2016 03:58
-
-
Save jwaldrip/f334ab1a5ba35b6c0113f3a08351f14b to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment