entity-routes logo
Docs

Route Scope#

Let's start by defining what we call a route scope.

It is a unique combination of 2 elements :

Each route scope will have unique responses schema generated from the mapping, itself made from the list of exposed properties on that scope.

Examples#

These are the routes generated from the Quick start example :

VerbPathEntityOperationRoute scope
POST/usersUsercreateuser.create
POST/users/mappingUsercreateuser.create.mapping
PUT/users/:id(\d+)Userupdateuser.update
PUT/users/:id(\d+)/mappingUserupdateuser.update.mapping
GET/users/:id(\d+)Usergetuser.get
GET/users/:id(\d+)/mappingUsergetuser.get.mapping
GET/usersUserlistuser.list
GET/users/mappingUserlistuser.list.mapping
DELETE/users/:id(\d+)Userdeleteuser.delete
POST/users/:UserId(\d+)/articlesArticlecreatearticle.create
GET/users/:UserId(\d+)/articlesArticlelistarticle.list
DELETE/users/:UserId(\d+)/articles/:id(\d+)Articledeletearticle.delete

Subresources#

This also means that subresources share the same route scope as their property entity router. For example, if you had an EntityRouter set up on the Article entity with ["create", "update", "list"] operations, you would have those routes generated :

VerbPathEntityOperationRoute scope
POST/articlesArticlecreatearticle.create
POST/articles/mappingArticlecreatearticle.create.mapping
PUT/articles/:id(\d+)Articleupdatearticle.update
PUT/articles/:id(\d+)/mappingArticleupdatearticle.update.mapping
GET/articlesArticlelistarticle.list
GET/articles/mappingArticlelistarticle.list.mapping

So, if you need to retrieve a subresource route mapping, it's actually just the subresource entity mapping for the same operation you're looking for !

Exposing properties#

With the @Groups decorator you can expose any property (or method), from any entity in the route scope of your choice.

What that means is that you can for example have a different mapping for the User creation route and the User update route. More on that later.

Of course this also means that you can have differents constraints for each route scope. TODO Validator docref

Inferred Mapping#

The mapping is a description of every properties exposed through the @Groups decorator for a specific route scope.

A route mapping endpoint is auto-generated for every basic operations and accessible by adding "/mapping" to the path of the route, the same HTTP verb as the operation it describes is used.

This mapping route will give you the response schema expected on the actual route it describes.

#
json
1{
2 "context": {
3 "operation": "details.mapping",
4 "entity": "user"
5 },
6 "routeMapping": {
7 "selectProps": ["name", "id"],
8 "relationProps": ["articles"],
9 "exposedProps": ["name", "id", "articles"],
10 "mapping": {
11 "articles": {
12 "selectProps": ["id"],
13 "relationProps": [],
14 "exposedProps": ["id"],
15 "mapping": {}
16 }
17 }
18 }

Scoped Validation#

TODO

Prev
Operations
Next
Introduction