Skip to content

Commit bda5546

Browse files
Merge pull request #49402 from v-thpra/azure-triage-fix-1016546
Technical Review 1016546: Consume REST web services in .NET MAUI apps
2 parents ceacefb + 998680a commit bda5546

14 files changed

+80
-80
lines changed

learn-pr/dot-net-maui/consume-rest-services-maui/1-introduction.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
unitType: introduction
66
title: "Introduction"
77
description: "Introduction to the module"
8-
ms.date: 10/31/2023
8+
ms.date: 03/05/2025
99
author: codemillmatt
1010
ms.author: masoucou
1111
ms.manager: markl

learn-pr/dot-net-maui/consume-rest-services-maui/2-detect-network-connectivity.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
unitType: unit
66
title: "Detect network connectivity"
77
description: "Learn how to detect whether an active connection to the Internet is available"
8-
ms.date: 10/31/2023
8+
ms.date: 03/05/2025
99
author: codemillmatt
1010
ms.author: masoucou
1111
ms.manager: markl
@@ -16,25 +16,25 @@ content: |
1616
quiz:
1717
title: Knowledge check
1818
questions:
19-
- content: "Which of the following is the best reason to check if you're connected to the Internet before running network code?"
19+
- content: "Which of the following answers is the best reason to check if you're connected to the Internet before running network code?"
2020
choices:
2121
- content: "You don't want to waste resources by performing operations that aren't going to do anything."
2222
isCorrect: false
23-
explanation: "No. You want to provide a good user experience if network connectivity is limited or unavailable"
24-
- content: "You want to provide a good user experience if network connectivity is limited or unavailable"
23+
explanation: "No. You want to provide a good user experience if network connectivity is limited or unavailable."
24+
- content: "You want to provide a good user experience if network connectivity is limited or unavailable."
2525
isCorrect: true
26-
explanation: "This is the correct answer"
27-
- content: "To establish a connection if you're not currently connected"
26+
explanation: "This answer is correct."
27+
- content: "You want to establish a connection if you're not currently connected."
2828
isCorrect: false
29-
explanation: "No. You want to provide a good user experience if network connectivity is limited or unavailable"
30-
- content: Suppose you are writing application that a user can run while traveling in a vehicle. If the vehicle enters a tunnel, the device might lose Internet connectivity. Which member of the `Connectivity` class should you use to detect the change in network connectivity?"
29+
explanation: "No. You want to provide a good user experience if network connectivity is limited or unavailable."
30+
- content: Suppose you're writing application that a user can run while traveling in a vehicle. If the vehicle enters a tunnel, the device might lose Internet connectivity. Which member of the `Connectivity` class should you use to detect the change in network connectivity?"
3131
choices:
32-
- content: "The `NetworkAccess` property"
32+
- content: "The `NetworkAccess` property."
3333
isCorrect: false
34-
explanation: "No. The `NetworkAccess` property informs you if you're connected to the Internet, but the app must check the value of this property to determine the network status. This means that you have to create a polling system to detect when the app lost the connection. It is better to use the `ConnectivityChanged` event that can run code automatically when the network status changes."
35-
- content: "The `ConnectionStatus` property"
34+
explanation: "No. The `NetworkAccess` property informs you if you're connected to the Internet, but the app must check the value of this property to determine the network status. This means that you have to create a polling system to detect when the app lost the connection. It's better to use the `ConnectivityChanged` event that can run code automatically when the network status changes."
35+
- content: "The `ConnectionStatus` property."
3636
isCorrect: false
37-
explanation: "No. There is no such property. Use the `ConnectivityChanged` event that can run code automatically when the network status changes."
38-
- content: "The `ConnectivityChanged` event"
37+
explanation: "No. There's no such property. Use the `ConnectivityChanged` event that can run code automatically when the network status changes."
38+
- content: "The `ConnectivityChanged` event."
3939
isCorrect: true
40-
explanation: "This is the correct answer"
40+
explanation: "This answer is correct."

learn-pr/dot-net-maui/consume-rest-services-maui/3-consume-rest-web-service.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
unitType: unit
66
title: "Consume a REST service with HttpClient"
77
description: "Learn how to connect to a REST web service and perform CRUD operations using HttpClient"
8-
ms.date: 10/31/2023
8+
ms.date: 03/05/2025
99
author: codemillmatt
1010
ms.author: masoucou
1111
ms.manager: markl
@@ -20,7 +20,7 @@ quiz:
2020
choices:
2121
- content: "`POST`"
2222
isCorrect: true
23-
explanation: "This is the correct answer."
23+
explanation: "This answer is correct."
2424
- content: "`PUT`"
2525
isCorrect: false
2626
explanation: "No. Use `PUT` to update an existing resource."
@@ -31,10 +31,10 @@ quiz:
3131
choices:
3232
- content: "`IsSuccessful`"
3333
isCorrect: false
34-
explanation: "No. The IsSuccessful is a property that is checked afterwards."
34+
explanation: "No. The `IsSuccessful` property is checked afterwards."
3535
- content: "`EnsureSuccessStatusCode`"
3636
isCorrect: true
37-
explanation: "This is the correct answer."
37+
explanation: "This answer is correct."
3838
- content: "`CheckStatusCode`"
3939
isCorrect: false
40-
explanation: "No. This isn't a valid method."
40+
explanation: "No. `CheckStatusCode` isn't a valid method."

learn-pr/dot-net-maui/consume-rest-services-maui/4-use-platform-specific-features.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ title: Use platform-specific network features
44
metadata:
55
unitType: unit
66
title: "Use platform-specific network features"
7-
description: "Learn about the platform-specific network capabilities available to .NET MAUI apps."
8-
ms.date: 10/31/2023
7+
description: "Learn about the platform-specific network capabilities available to .NET Multi-platform App UI (MAUI) apps."
8+
ms.date: 03/05/2025
99
author: codemillmatt
1010
ms.author: masoucou
1111
ms.manager: markl

learn-pr/dot-net-maui/consume-rest-services-maui/5-exercise-consume-rest-web-service.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
unitType: exercise
66
title: "Exercise - Consume a REST service with HttpClient"
77
description: "Exercise - Consume a REST service with HttpClient"
8-
ms.date: 10/31/2023
8+
ms.date: 03/05/2025
99
author: codemillmatt
1010
ms.author: masoucou
1111
ms.manager: markl

learn-pr/dot-net-maui/consume-rest-services-maui/6-summary.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ title: Summary
44
metadata:
55
unitType: Summary
66
title: "Summary"
7-
description: "Summary of the consuming REST services with .NET MAUI module"
8-
ms.date: 10/31/2023
7+
description: "Summary of the module."
8+
ms.date: 03/05/2025
99
author: codemillmatt
1010
ms.author: masoucou
1111
ms.manager: markl

learn-pr/dot-net-maui/consume-rest-services-maui/includes/1-introduction.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
Many modern applications make use of REST web services to provide access to data or other features such as cloud storage. This is especially true of mobile applications running on phones and tablet devices. Most apps that incorporate social aspects and shared media are reliant on connectivity to these services. Without connectivity, many apps are limited in their functionality. They might be restricted to features cached locally on the device. A well-designed app can transparently detect whether a network connection is available and adjust its feature set accordingly.
1+
Many modern applications make use of REST web services to provide access to data or other features such as cloud storage. Especially, mobile applications running on phones and tablet devices. Most apps that incorporate social aspects and shared media are reliant on connectivity to these services. Without connectivity, many apps are limited in their functionality and might be restricted to features cached locally on the device. A well-designed app can transparently detect whether a network connection is available, and then adjust its feature set accordingly.
22

33
Imagine that you work as a developer for a power-utilities company. You're creating an app that your engineers can use when they visit customer sites to perform routine servicing. During a site visit, an engineer might need to order replacement parts. Part of the app should allow an engineer to quickly look up the details for a part. Your company previously built a REST web service that provides information about electrical components and parts. This web service runs in Azure. The app must be able to connect to this web service to retrieve information about parts.
44

5-
In this module, you'll build a .NET MAUI application that consumes data from a REST web service. You'll start by determining if your device is connected to the Internet and only attempt to communicate with the web service if you have an active connection. Then, you'll use **HttpClient** to perform basic CRUD operations on a hosted REST web service. Finally, you'll configure the native networking stacks on each device to implement secure communications between the app and the web service.
5+
In this module, you build a .NET Multi-platform App UI (MAUI) application that consumes data from a REST web service. You start by determining if your device is connected to the Internet and only attempt to communicate with the web service if you have an active connection. Then, you use **HttpClient** to perform basic CRUD operations on a hosted REST web service. Finally, you configure the native networking stacks on each device to implement secure communications between the app and the web service.
66

77
## Learning objectives
88

9-
In this module, you learned how to:
9+
In this module, you learn how to:
1010

1111
- Detect if your device is connected to the internet.
1212
- Consume a REST web service by using **HttpClient**.

learn-pr/dot-net-maui/consume-rest-services-maui/includes/2-detect-network-connectivity.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ In this unit, you protect your application by detecting when your users lose the
44

55
## Why detect network connectivity on mobile applications?
66

7-
Detecting if you have an Internet connection on a mobile application is important because mobile devices can frequently lose their connection. This may be due to poor coverage by a network service provider, or being in an environment that has limited or no reception, such as a tunnel, deep valley, or high mountain. There are also different types of network connectivity. If you're located in an environment that provides WiFi connectivity, you typically have higher bandwidth than if you're dependent on cellular access. You might still be able to connect to the Internet, but some operations, such as streaming video content, might be slower (and expensive) over a cellular link compared to a WiFi connection.
7+
Detecting if you have an Internet connection on a mobile application is important. Mobile devices can frequently lose their connection due to poor coverage by a network service provider. Or if you're in an environment with limited or no reception, such as a tunnel, deep valley, or high mountain. There are also different types of network connectivity. If you're located in an environment that provides WiFi connectivity, you typically have higher bandwidth than if you're dependent on cellular access. You might still be able to connect to the Internet, but some operations, such as streaming video content, might be slower (and expensive) over a cellular link compared to a WiFi connection.
88

99
Because mobile devices have these challenges, you must write code to protect against them. If you don't, and your application attempts to perform operations that use the internet, your application might stop responding.
1010

@@ -16,9 +16,9 @@ In this example, the application developer informs the user that they don't have
1616

1717
## Detect network connectivity
1818

19-
To check for network connectivity in a .NET MAUI app, use the `Connectivity` class. This class exposes a property called `NetworkAccess` and an event named `ConnectivityChanged`. You can use these members to detect changes in the network.
19+
To check for network connectivity in a .NET Multi-platform App UI (MAUI) app, use the `Connectivity` class. This class exposes a property called `NetworkAccess` and an event named `ConnectivityChanged`. You can use these members to detect changes in the network.
2020

21-
You access the `NetworkAccess` property through another property called `Current`. This is the mechanism that `Connectivity` takes to access the platform-specific implementation.
21+
You access the `NetworkAccess` property through another property called `Current`. The `Connectivity` class uses the `Current` property to access the platform-specific implementation.
2222

2323
The `NetworkAccess` property returns a value from the `NetworkAccess` enumeration. The enumeration has five values: `ConstrainedInternet`, `Internet`, `Local`, `None`, and `Unknown`. If the `NetworkAccess` property returns a value of `NetworkAccess.None`, then you know you don't have a connection to the Internet, and you shouldn't run networking code. This mechanism is portable across platforms. The following code shows an example:
2424

learn-pr/dot-net-maui/consume-rest-services-maui/includes/3-consume-rest-web-service.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
Many modern web services implement the REST architecture. This structure enables a web service to expose operations and data through a series of well-defined endpoints. The requests that client apps send to a REST web service to retrieve, modify, or create, or delete data use a predefined set of **verbs**. A REST web service responds to these requests in a standard manner. This approach makes it easier to construct client apps.
1+
Many modern web services implement the REST architecture. This structure enables a web service to expose operations and data through a series of well-defined endpoints. The requests that client apps send to a REST web service to retrieve, modify, create, or delete data use a predefined set of **verbs**. A REST web service responds to these requests in a standard manner. This approach makes it easier to construct client apps.
22

3-
The REST model is built on top of the HTTP protocol. A .NET MAUI application can send requests to a REST web service by using the `HttpClient` class. In this unit, you'll learn about `HttpClient` and how to use it to interact with a REST web service.
3+
The REST model is built on top of the HTTP protocol. A .NET Multi-platform App UI (MAUI) application can send requests to a REST web service by using the `HttpClient` class. In this unit, you learn about `HttpClient` and how to use it to interact with a REST web service.
44

55
## What is the HttpClient class?
66

7-
`HttpClient` is a .NET class that an app can use to send HTTP requests and receive HTTP responses from a REST web service. A set of URIs identifies the resources that the web service exposes. A URI combines the address of the web service with the name of a resource available at that address.
7+
`HttpClient` is a .NET class that an app can use to send HTTP requests and receive HTTP responses from a REST web service. A set of Uniform Resource Identifiers (URI)s identifies the resources that the web service exposes. A URI combines the address of the web service with the name of a resource available at that address.
88

99
The `HttpClient` class uses a task-based API for performance, and gives you access to information in request messages such as HTTP headers and status codes, as well as message bodies that contain the actual data being sent and received.
1010

@@ -21,7 +21,7 @@ var client = new HttpClient();
2121

2222
## Perform CRUD operations with an HttpClient object
2323

24-
A REST web service enables a client to perform operations against data through a set of HTTP verbs. The HTTP verb's job is to indicate the desired action to be performed on a resource. There are many HTTP verbs, but the four most common are `POST`, `GET`, `PUT`, and `DELETE`. A service can implement these verbs to enable a client application to manage the lifecycle of objects by performing Create, Read, Update, and Delete (CRUD) operations, as follows:
24+
A REST web service enables a client to perform operations against data through a set of HTTP verbs. The HTTP verb's job is to indicate the desired action to be performed on a resource. There are many HTTP verbs, but the four most common are `POST`, `GET`, `PUT`, and `DELETE`. A service can implement these verbs to enable a client application to manage the lifecycle of objects by performing Create, Read, Update, and Delete (CRUD) operations:
2525

2626
- The `POST` verb indicates that you want to create a new resource.
2727

@@ -80,7 +80,7 @@ In this example, the result is returned as a string and only contains the respon
8080

8181
### Update a resource with HttpClient
8282

83-
To update a resource by using `HttpClient`, use an `HttpRequestMessage` initialized with a **PUT** verb. The following code is similar to that required to create a new resource:
83+
To update a resource by using `HttpClient`, use an `HttpRequestMessage` initialized with a **PUT** verb. The following code is similar to the code required to create a new resource:
8484

8585
```csharp
8686
HttpClient client = new HttpClient();
@@ -92,7 +92,7 @@ HttpResponseMessage response = await client.SendAsync(message);
9292
```
9393

9494
> [!NOTE]
95-
> The fundamental difference between `POST` and `PUT` is idempotency. If you repeat the same `PUT` request several times, the same resource will be updated with the same data, and the effect is the same as if the request had been sent only once. If you issue the same `POST` request several times, the result will be the REST service creating multiple copies of the resource.
95+
> The fundamental difference between `POST` and `PUT` is idempotency. If you repeat the same `PUT` request several times, the same resource is updated with the same data, and the effect is the same as if the request was sent only once. If you issue the same `POST` request several times, the REST service creates multiple copies of the resource.
9696
9797
### Delete a resource with HttpClient
9898

@@ -113,11 +113,11 @@ All HTTP requests return a response message. The data in the response depends on
113113

114114
The response body of a `POST` request returns a copy of the resource that was created, but the response body of a `PUT` request should be empty.
115115

116-
You should always check and handle the status code in the response message. If this status code is in the 200 range (200, 201, 202, and so on), then the operation is deemed to have been successful, although further information might be required later.
116+
You should always check and handle the status code in the response message. If this status code is in the 200 range (200, 201, 202, and so on), then the operation is considered successful, although further information might be required later.
117117

118-
A status code in the 300 range indicates that the request might have been redirected by the web service to a different address, possibly as the result of a resource moving to a different location.
118+
A status code in the 300 range might indicate that the web service redirected the request to a different address, possibly as the result of a resource moving to a different location.
119119

120-
A status code in the 400 range indicates a client or application error. For example, status code 403 means that the web service requires the user to be authenticated, but the app hasn't done so. Status code 404 occurs when the app attempts to access a resource that doesn't exist.
120+
A status code in the 400 range indicates a client or application error. For example, status code 403 means that the web service requires the user to be authenticated, but the app didn't do the authentication. Status code 404 occurs when the app attempts to access a resource that doesn't exist.
121121

122122
Status codes in the 500 range are indicative of a server-side error, such as the service being unavailable or too busy to handle the request.
123123

0 commit comments

Comments
 (0)