A shorthand is a simple way to define a route handler for common API scenarios. Here’s a reference of each shorthand, along with the raw route handler that the shorthand represents.
In Mirage 0.1, shorthands responded with objects and arrays directly from the database. In 0.2, shorthands return Models and Collections, meaning you can customize the format of the response in the serializer layer.
Shorthands use default status codes, based on the HTTP verb:
GET, PUT and DEL are 200
POST is 201
GET shorthands
Collection
Shorthand
Expanded
Object
Shorthand
Expanded
Array of Objects
For example, GET /contacts?ids=1,3
Shorthand
Expanded
Note: there used to be a Single record with related records shorthand. You should now use serializers and relationships to solve this problem.
POST shorthands
Creating a resource
Shorthand
Expanded
For this POST shorthand to work, Mirage needs to know the format of the JSON payload your Ember app sends along with the request, so that it can insert the appropriate data into the database. See the note on normalize in the Serializer docs for more information.
PUT shorthands
Update a resource
Shorthand
Expanded
For this PUT shorthand to work, Mirage needs to know the format of the JSON payload your Ember app sends along with the request, so that it can insert the appropriate data into the database. See the note on normalize in the Serializer docs for more information.
DELETE shorthands
Remove a resource
Shorthand
Expanded
Remove a resource and related models
To use this shorthand, make sure you have the appropriate hasMany/belongsTo relationships defined on your models.
Shorthand
Expanded
Resource helper
For handling generic CRUD, you can use resource helper which will take care of defining all shorthands. The following examples are equivalent:
Resource
Equivalent shorthands
You can also whitelist which route handlers will be defined using only option:
Resource
Equivalent shorthands
or which route handlers shouldn’t be defined using except option:
Resource
Equivalent shorthands
If your route path and collection names do not match, you can define a relative
or absolute path using the path option:
Resource
Equivalent shorthands
Here is the full reference of actions’ names you can pass to only / except options and the shorthands they stand for: