Skip to content

Commit 8acecad

Browse files
committed
Update native-mobile-backend.md
1 parent 2c678a0 commit 8acecad

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

aspnetcore/mobile/native-mobile-backend.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ To test it out yourself against the ASP.NET Core app created in the next section
3838

3939
Android emulators don't run on the local machine and use a loopback IP (10.0.2.2) to communicate with the local machine. Use .NET MAUI's [DeviceInfo](/dotnet/maui/platform-integration/device/information) class to detect the operating system the app is running on to use the correct URL.
4040

41-
Navigate to the [`TodoREST`](https://github.com/dotnet/maui-samples/tree/main/9.0/WebServices/TodoREST) project and open the [`Constants.cs`](https://github.com/dotnet/maui-samples/blob/main/9.0/WebServices/TodoREST/TodoREST/Constants.cs) file. The `Constants.cs` file contains the following configuration.
41+
Navigate to the [`TodoREST`](https://github.com/dotnet/maui-samples/tree/main/9.0/WebServices/TodoREST) project and open the [`Constants.cs`](https://github.com/dotnet/maui-samples/blob/main/10.0/WebServices/TodoREST/TodoREST/Constants.cs) file. The `Constants.cs` file contains the following configuration.
4242

43-
:::code language="csharp" source="~/../maui-samples/9.0/WebServices/TodoREST/TodoREST/Constants.cs" highlight="10":::
43+
:::code language="csharp" source="~/../maui-samples/blob/main/10.0/WebServices/TodoREST/TodoREST/Constants.cs" highlight="10":::
4444

4545
You can optionally deploy the web service to a cloud service such as Azure and update the `RestUrl`.
4646

@@ -57,27 +57,27 @@ The app should respond to all requests made over HTTPS to port 5001.
5757
5858
Add a model class to represent todo items. Mark required fields with the `[Required]` attribute:
5959

60-
:::code language="csharp" source="~/../maui-samples/9.0/WebServices/TodoREST/TodoAPI/Models/TodoItem.cs":::
60+
:::code language="csharp" source="~/../maui-samples/blob/main/10.0/WebServices/TodoREST/TodoAPI/Models/TodoItem.cs":::
6161

6262
API methods require defining to work with data. Use the same `ITodoRepository` interface the sample uses:
6363

64-
:::code language="csharp" source="~/../maui-samples/9.0/WebServices/TodoREST/TodoAPI/Interfaces/ITodoRepository.cs":::
64+
:::code language="csharp" source="~/../maui-samples/blob/main/10.0/WebServices/TodoREST/TodoAPI/Interfaces/ITodoRepository.cs":::
6565

6666
For this sample, the repository implementation just uses a private collection of items:
6767

68-
:::code language="csharp" source="~/../maui-samples/9.0/WebServices/TodoREST/TodoAPI/Services/TodoRepository.cs":::
68+
:::code language="csharp" source="~/../maui-samples/blob/main/10.0/WebServices/TodoREST/TodoAPI/Services/TodoRepository.cs":::
6969

7070
Configure the implementation in `Program.cs`:
7171

72-
:::code language="csharp" source="~/../maui-samples/9.0/WebServices/TodoREST/TodoAPI/Program.cs" highlight="5":::
72+
:::code language="csharp" source="~/../maui-samples/blob/main/10.0/WebServices/TodoREST/TodoAPI/Program.cs" highlight="5":::
7373

7474
## Creating the Controller
7575

76-
Add a new controller to the project, [TodoItemsController](https://github.com/dotnet/maui-samples/blob/main/9.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs). It should inherit from <xref:Microsoft.AspNetCore.Mvc.ControllerBase>. Add a `Route` attribute to indicate that the controller handles requests made to paths starting with `api/todoitems`. The `[controller]` token in the route is replaced by the name of the controller (omitting the `Controller` suffix), and is especially helpful for global routes. Learn more about [routing](../fundamentals/routing.md).
76+
Add a new controller to the project, [TodoItemsController](https://github.com/dotnet/maui-samples/blob/main/10.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs). It should inherit from <xref:Microsoft.AspNetCore.Mvc.ControllerBase>. Add a `Route` attribute to indicate that the controller handles requests made to paths starting with `api/todoitems`. The `[controller]` token in the route is replaced by the name of the controller (omitting the `Controller` suffix), and is especially helpful for global routes. Learn more about [routing](../fundamentals/routing.md).
7777

7878
The controller requires an `ITodoRepository` to function; request an instance of this type through the controller's constructor. At runtime, this instance is provided using the framework's support for [dependency injection](../fundamentals/dependency-injection.md).
7979

80-
:::code language="csharp" source="~/../maui-samples/9.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs" id="snippetDI":::
80+
:::code language="csharp" source="~/../maui-samples/blob/main/10.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs" id="snippetDI":::
8181

8282
This API supports four different HTTP verbs to perform CRUD (Create, Read, Update, Delete) operations on the data source. The simplest of these is the Read operation, which corresponds to an HTTP `GET` request.
8383

@@ -132,7 +132,7 @@ For more details on jq installation, see [jq](https://jqlang.github.io/jq/downlo
132132

133133
Requesting a list of items is done with a GET request to the `List` method. The `[HttpGet]` attribute on the `List` method indicates that this action should only handle GET requests. The route for this action is the route specified on the controller. You don't necessarily need to use the action name as part of the route. You just need to ensure each action has a unique and unambiguous route. Routing attributes can be applied at both the controller and method levels to build up specific routes.
134134

135-
:::code language="csharp" source="~/../maui-samples/9.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs" id="snippet":::
135+
:::code language="csharp" source="~/../maui-samples/blob/main/10.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs" id="snippet":::
136136

137137
# [macOS](#tab/macos)
138138

@@ -195,11 +195,11 @@ By convention, creating new data items is mapped to the HTTP `POST` verb. The `C
195195

196196
Inside the method, the item is checked for validity and prior existence in the data store, and if no issues occur, it's added using the repository. Checking `ModelState.IsValid` performs [model validation](../mvc/models/validation.md), and should be done in every API method that accepts user input.
197197

198-
:::code language="csharp" source="~/../maui-samples/9.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs" id="snippetCreate":::
198+
:::code language="csharp" source="~/../maui-samples/blob/main/10.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs" id="snippetCreate":::
199199

200200
The sample uses an `enum` containing error codes that are passed to the mobile client:
201201

202-
:::code language="csharp" source="~/../maui-samples/9.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs" id="snippetErrorCode":::
202+
:::code language="csharp" source="~/../maui-samples/blob/main/10.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs" id="snippetErrorCode":::
203203

204204
In the terminal, test adding new items by calling the following curl command using the `POST` verb and providing the new object in JSON format in the Body of the request.
205205

@@ -242,7 +242,7 @@ The method returns the newly created item in the response.
242242

243243
Modifying records is achieved using HTTP `PUT` requests. Other than this change, the `Edit` method is almost identical to `Create`. If the record isn't found, the `Edit` action returns a `NotFound` (404) response.
244244

245-
:::code language="csharp" source="~/../maui-samples/9.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs" id="snippetEdit":::
245+
:::code language="csharp" source="~/../maui-samples/blob/main/10.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs" id="snippetEdit":::
246246

247247
To test with curl, change the verb to `PUT`. Specify the updated object data in the Body of the request.
248248

@@ -279,7 +279,7 @@ This method returns a `NoContent` (204) response when successful, for consistenc
279279

280280
Deleting records is accomplished by making `DELETE` requests to the service, and passing the ID of the item to be deleted. As with updates, requests for items that don't exist receive `NotFound` responses. Otherwise, a successful request returns a `NoContent` (204) response.
281281

282-
:::code language="csharp" source="~/../maui-samples/9.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs" id="snippetDelete":::
282+
:::code language="csharp" source="~/../maui-samples/blob/main/10.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs" id="snippetDelete":::
283283

284284
Test with curl by changing the HTTP verb to `DELETE` and appending the ID of the data object to delete at the end of the URL. Nothing is required in the Body of the request.
285285

0 commit comments

Comments
 (0)