Endpoints
Every API can have multiple endpoints. They can be used to structure different parts of the API or to serve multiple API versions at once (i.e. a v1 and a v2 endpoint). An Endpoint consists of interfaces and resources.
Elements
Interfaces
If you add an interface to an endpoint all of its public methods will be able to called from outside.
Resources
RESTful resources require a repository and a resource class. The resource class is used to decouple the API from the domain model. This makes it possible to rename fields, return more or less fields or to create multiple specialized resources from the same model.
Exception Handling
Depending on the type of the thrown exception the API will return a different http status code. This provides the caller with additional information on why a call has failed.
InvalidArgumentException → 400 Bad Request
Everything else → 500 Internal Server Error
Â