Notes on Siren
We use Siren Hypermedia Format for exchange. We like it a lot but have found some limitations which needed us to deviate from the standard.
Action parameters
Siren Actions uses HTML5 input types to specify parameters for actions. We wanted to have a richer experience and decided to use JSON schema to hand us information about the parameters of an action.
To stay close to the standard we:
fieldscontain exactly one field and thenameof that field is set to the parameter object name.- Add a URL to the actions schema in the
classof a field. The server is expected to deliver the JSON schema when this link is resolved. typeis set to"application/json"to indicate we expect a JSON.valuemay contain prefilled values as a JSON object
Example:
{
"class": [
"CustomersRoot"
],
"title": "The Customers API",
"properties": {},
"entities": [],
"actions": [
{
"name": "CreateCustomer",
"title": "Request creation of a new Customer.",
"method": "POST",
"href": "http://localhost:5000/Customers/CreateCustomer",
"type": "application/json",
"class": [
"ParameterAction"
],
"fields": [
{
"name": "CreateCustomerParameters",
"type": "application/json",
"class": [
"http://localhost:5000/ActionParameterTypes/CreateCustomerParameters"
]
}
]
},
],
...
}
An acceptable JSON parameter (send as array of objects to stay close to the specification) for the action looks like this:
[{"CreateCustomerParameters":
{
"Name":"Hans Schmid"
}
}]
Also we accept a short form without the container array:
{
"CreateCustomerParameters":
{
"Name":"Hans Schmid"
}
}
File upload
File upload requires the server to present some information to the clients.
We send the following structure:
typeof the action ismultipart/form-datato indicate how to send the datafieldscontain the information for the uploadtypeisfileto stay close to the siren standard using HTML5 input typesaccept: a comma separated list of file type specifiers. See: MDN: Unique file type specifiersmaxFileSizeBytes: max size of the uploadallowMultiple: Is it allowed to send multiple files
Example:
{
...
"actions": [
{
"name": "Upload",
"title": "Uploads data to the system",
"method": "POST",
"href": "https://myhost.com/api/Data/UploadData",
"type": "multipart/form-data",
"class": [
"FileUploadAction"
],
"fields": [
{
"name": "UploadFiles",
"type": "file",
"accept": ".png, image/*'",
"maxFileSizeBytes": 209715200,
"allowMultiple": false
}
]
},