Directive ‘via_post’
via_post { ... }
The directive activates the routing of POST requests to the application. POST requests send JSON data in order to create new resources/model-instances on the server and return the created resource.
via_post
may appear inside the directives:
collection
association
(plural)
The directive’s block contains allow
(required) and
handler
directives (optional), which define run-time code to decide on authorization and contain custom business logic if the built-in default handlers are not appropriate.
To create new resources the POST request’s URI must specify the base resource under which the new resource shall be available. This can be either the :all
collection or a plural association.
Example
Request:
POST https://example.com/people
{"first_name": "Elinor", "last_name": "Langosh"}
Response:
Request:
POST https://example.com/people/102/posts
{"title": "My First Toast", "text": "It was a bit dry."}
Response: