Building a RESTful API with ASP.NET Core 3 Flashcards Preview

.NET / C# > Building a RESTful API with ASP.NET Core 3 > Flashcards

Flashcards in Building a RESTful API with ASP.NET Core 3 Deck (105)
Loading flashcards...
1

Is rest a standard? is it protocol agnostic?

NO. an arch style... it is protocol agnostico

2

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).

3

What is the payload?

Is the data that is sent and/or retrieved along with the request/response.

4

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.

5

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

6

What is the level 1 - Resources of RMM?

Each resource is mapped to a URI; using post verb only

7

What is the level 2 - Verbs of RMM?

Correct HTTP verbs and status codes are used;

8

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).

9

Which API level can be considered a precondition to a RESTful api?

Level 3.

10

Can the URI api/authors be followed by another noun?

NO. should be followed with an ID.

11

Where to add filters, sorting orders?

As a query string.. api/customer?orderby=name

12

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]

13

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.

14

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

15

How to interact with resources via HTTP methods?

https://pasteboard.co/JstVwBx.png

16

How to create two http gets to the same source with disambiguation?

[HTTPGet("{authorId:guid}")]
[HTTPGet("{authorId:int}")]

17

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

18

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)...

19

What is the most comon 500 hundred status code?what does it mean?

internal error - something bad happened to the server - try again

20

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.

21

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

22

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

23

How to proper handle unsupported formats in a way that the api returns a 406 error?

via services.addcontroller(s => s.ReturnHttpNotAcceptable = true);

24

how to add xml as a supported fortmat in asp?

s.addcontroller().addxmldatacontractserializerformatters();

25

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

26

Should I always return IActionResult? What's better for things like swagger?

return ActionResult>

27

What to use to map entity properties to dto object?

AutoMapper

28

Should i simply install automapper? why not?

not... install automapper.extensions.microsoft.dependencyinjection because it plays better with aspnet DI system

29

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)

30

How to handle exceptions in the API in a customized way othen than just return a status code 500?

by doing an app.UseExceptionHandler(appbuilder => {... appbuilder.run...})