Flashcards in Building a RESTful API with ASP.NET Core 3 Deck (105)
Is rest a standard? is it protocol agnostic?
NO. an arch style... it is protocol agnostico
What are the 6 contraintaints (design decisions) that REST has?
1 - Uniform Interfaces: API and consumers share one single technical interface: API;
2 - Client-Server: They are completelly separated;
3 - Statelessness: state is contained within the request;
4 - Layered system: layers can be added or removed in a transparent way to other layers;
5 - Cacheable: each RESPONSE message must explicitly state if it can be cached or not (ETag, lat-modified and etc)
6 - Code on demand (optional): server can extend client functionality (usually applicable for webapps).
What is the payload?
Is the data that is sent and/or retrieved along with the request/response.
What is the Richardson Maturity Model (RMM) and how it relates to REST?
It is a set of maturity levels that dictates how much you actually use from the REST standards, or how mature it is.
What is the level 0 - (swamp of POX - plain old XML) of RMM?
You use a single endpoint with a set of statefull calls to achieve a goal; usually using xml
What is the level 1 - Resources of RMM?
Each resource is mapped to a URI; using post verb only
What is the level 2 - Verbs of RMM?
Correct HTTP verbs and status codes are used;
What is the level 3 - Hypermedia of RMM? Which benefit does it bring?
The API supports Hypermedia as the engine of the application state (HATEOAS). It brings links to other actions/resources (discoverability).
Which API level can be considered a precondition to a RESTful api?
Can the URI api/authors be followed by another noun?
NO. should be followed with an ID.
Where to add filters, sorting orders?
As a query string.. api/customer?orderby=name
What a simple controller must have to behave like an endpoint?
data anotaded as [APIController], extending ControllerBase, defining the Route[("api/authors")] data anotation to the controller and defining the data anotation verb to the action [HTTPGet]
What is a convention-based routing? When is it used the most?
endpoints are added to actions on a controller following a convention (explicitly defined). usually used for web applications.
What is attribute-based routing?When is it used the most?
The routing is defined via the combinations of the controller name and data anotations in the action methods inside the controllers. used the most for APIs
How to interact with resources via HTTP methods?
How to create two http gets to the same source with disambiguation?
What are the 3 most important 200 status codes which verb uses it?
200 - Ok - Get, Success
201 - Ok - Post, Created
204 - Ok - Delete, No content
What are the 9 most important 400 status codes?
400 - Bad request - Generic
401 - Unauthorized (authentication issues)
403 - Forbidden (authorization issues)
404 - not found
405 - method not allow (e.g send a post to the authors endpoint)
406 - not acceptable (the payload response format asked is not supported)
409 - Conflict (used to handle concurrency issues: the data has been changed by someone else)
415 - same as 406, but the issue is with the REQUEST payload
422 - unprocessable entity - semantic mistakes (validation)...
What is the most comon 500 hundred status code?what does it mean?
internal error - something bad happened to the server - try again
What is the difference between errors and faults?
errors are correctly thrown when something is wrong with the request. and faults means that the API failed to process a correct request.
What is the benefits of using Ok() instead of new JasonResult()?
Ok is more readable and deals with other formats of data other than the jason
What formatters and content negotiation mean?
the client can demand the response in a specific format, and the server can deman the request in a specific format
How to proper handle unsupported formats in a way that the api returns a 406 error?
via services.addcontroller(s => s.ReturnHttpNotAcceptable = true);
how to add xml as a supported fortmat in asp?
What outer facing (DTO) vs entity model means?
means that our internal entity model should NOT be directly exposed to the external world. instead we should use outer facing models and translate into them via automapper
Should I always return IActionResult? What's better for things like swagger?
What to use to map entity properties to dto object?
Should i simply install automapper? why not?
not... install automapper.extensions.microsoft.dependencyinjection because it plays better with aspnet DI system
Where mappings are stored? How to add custom mappings (aka projections)?
in the profiles folder, create one for each dto object... inheriting the dto object from map and doing a forMember (if custom)