20. Advanced Web Service Features Flashcards

1
Q

What are Advanced Web Service Features?

A

The features described in this chapter provide greater control over how ASP.NET Core web services work, including managing the data sent to the client and the format used for that data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why are Advanced Web Service Features useful?

A

The default behaviors provided by ASP.NET Core don’t meet the needs of every project, and the features described in this chapter allow web services to be reshaped to fit specific requirements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How are Advanced Web Service Features used?

A

The common theme for the features in this chapter is altering the responses produced by action methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Are there any pitfalls or limitations with Advanced Web Service Features?

A

It can be hard to decide how to implement web services, especially if they are consumed by third-party clients. The behavior of a web service becomes fixed as soon as clients start using a web service, which means that careful thought is required when using the features described in this chapter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Are there any alternatives to Advanced Web Service Features?

A

The features described in this chapter are optional, and you can rely on the default behaviors of ASP.NET Core web services.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain the include method.

A

The Include method tells Entity Framework Core to follow a relationship in the database and load the related data.

Example:
return await context.Suppliers
.Include(s => s.Products)
.FirstAsync(s => s.SupplierId == id);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does a patch request do?

A

Sends just the changes to the web service rather than a complete replacement object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain JSON patch

A

PATCH request, which sends just the changes to the web service rather than a complete replacement object.
The client is going to send the web service JSON data like this in its HTTP PATCH requests:

[
{ “op”: “replace”, “path”: “Name”, “value”: “Surf Co”},
{ “op”: “replace”, “path”: “City”, “value”: “Los Angeles”},
]

A JSON Patch document is expressed as an array of operations. Each operation has an op property, which specifies the type of operation, and a path property, which specifies where the operation will be applied.
For the example application—and, in fact, for most applications—only the replace operation is required, which is used to change the value of a property. This JSON Patch document sets new values for the Name and City properties. The properties defined by the Supplier class not mentioned in the JSON Patch document will not be modified.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain accept headers in requests.

A

Most clients include an Accept header in a request, which specifies the set of formats that they are willing to receive in the response, expressed as a set of MIME types.
If formats don’t allign, by default, the MVC Framework is configured to only use JSON. Rather than return an error, the MVC Framework sends JSON data in the hope that the client can process it, even though it was not one of the formats specified by the request Accept header.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to Restrict the Formats Received by an Action Method?

A

The Consumes attribute can be applied to action methods to restrict the data types it will handle.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is OpenAPI?

A

The OpenAPI specification, which is also known as Swagger, describes web services in a way that can be understood by other programmers and consumed programmatically.
The OpenAPI discovery process requires a unique combination of the HTTP method and URL pattern for each action method. Therefore the process doesn’t support the Consumes attribute.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly