@determinacy/interface v1.0.3
interface
interface is a utility to build restful, jsonapi compliant apis.
getting started
to create an interface project, go ahead and run the following command:
$> interface create <directory>
resources
resources are defined in the resources
folder using jsonschema.
beside the data model of the resource, the following information is defined:
applicability
{
"$id": "product",
"applicability": {
"create": true,
"read": true,
"update": true,
"delete": true
},
"type": "object",
"properties": {
"id": {
"type": "string",
"readOnly": true
},
"supplier": {
"$ref": "supplier"
}
},
"required": [
"id"
],
"additionalProperties": false
}
used to indicate applicable CRUD operations on the resource.
relationships
relationships are reflected in the resource using the $ref syntax, where the value is the identifier of the relating resource.
{
"$id": "product",
"applicability": {
"create": true,
"read": true,
"update": true,
"delete": true
},
"type": "object",
"properties": {
"id": {
"type": "string",
"readOnly": true
},
"supplier": {
"$ref": "supplier"
}
},
"required": [
"id"
],
"additionalProperties": false,
"datasource": "postgresql"
}
datasource
{
"$id": "product",
"applicability": {
"create": true,
"read": true,
"update": true,
"delete": true
},
"type": "object",
"properties": {
"id": {
"type": "string",
"readOnly": true
},
"supplier": {
"$ref": "supplier"
}
},
"required": [
"id"
],
"additionalProperties": false,
"datasource": "mongodb"
}
controllers
after resources are defined with their applicability, relationships and datasources configuration, go ahead and run:
$> interface controller generate
the generated controllers are in the controllers
folder, the generate
command makes sure that the controllers reflect resources definitions.
you can run the generate
command whenever the resources definition changes, it will only add missing controllers without overriding or deleting existing controllers, so your changes are always there, still, you can always clean up unneeded controllers by running:
$> interface controller clean
datasources
different resources can have different datasources.
to work with a custom datasource, its interface should be defined in the datasources folder.