@@ -21,31 +21,30 @@ Tutorial: Create a RESTful API with the {+driver-short+} Driver
2121Overview
2222--------
2323
24- In this tutorial, you will learn how to create a RESTful API with endpoints that
25- perform basic create, read, update, and delete (CRUD) operations across MongoDB
26- Atlas.
24+ In this tutorial, you can learn how to create a RESTful API with endpoints that
25+ perform basic create, read, update, and delete (CRUD) operations across
26+ collections in a MongoDB Atlas cluster .
2727
2828Prequisites
2929-----------
3030
31- To complete this tutorial, you must have the following:
31+ Before you start this tutorial, perform the following actions :
3232
33- - An `Atlas account
34- <https://account.mongodb.com/account/register?tck=docs_atlas>`__ with a
35- deployed and configured MongoDB Atlas cluster that is M0 or higher.
33+ - Set up a MongoDB Atlas account and deploy and configure a cluster that is M0
34+ or higher. To view instructions, see the :atlas:`Get Started with Atlas </getting-started>` guide.
3635
37- - .NET 6.0 or higher `installed <https://dotnet.microsoft.com/en-us/download>`__ on your machine.
36+ - Install .NET 6.0 or later on your machine. To install .NET, visit the
37+ `Microsoft .NET download page <https://dotnet.microsoft.com/en-us/download>`__.
3838
39- To learn how to get started with MongoDB Atlas and how to load sample data, see the
40- :atlas:`Get Started with Atlas Guide </getting-started>`.
41-
42- This tutorial uses .NET Core 8.0, but you can use any version later than .NET 6.0.
39+ .. note::
40+
41+ This tutorial uses .NET Core 8.0, but you can use any version later than .NET 6.0.
4342
4443Set Up Your Project
4544-------------------
4645
47- You can create a new .NET Core project using the web application template that
48- Microsoft offers. To do this, run the following commands in your terminal :
46+ Run the following commands in your terminal to create a new .NET Core project
47+ that uses a web application template :
4948
5049.. code-block:: bash
5150
@@ -60,21 +59,20 @@ To add the {+driver-short+} to your project as a dependency, run the following c
6059
6160The preceding commands create a new web application project for .NET core named
6261``MongoExample`` and install the latest {+driver-short+}. The template project
63- includes some boilerplate files. During this tutorial, you will add to these
64- files and remove some of the boilerplate code to create a RESTful API.
62+ includes some boilerplate files that you modify to implement a RESTful API.
6563
6664Design a Document Model and Database Service
6765--------------------------------------------
6866
69- In this section, you will create and configure your MongoDB service and define
67+ In this section, you can create and configure your MongoDB service and define
7068the data model for your RESTful API.
7169
7270.. procedure:: Create a MongoDB Service
7371 :style: connected
7472
7573 .. step:: Create the MongoDBSettings class
7674
77- Your MongoDB service will be responisble for establishing a connection and
75+ Your MongoDB service is responsible for establishing a connection and
7876 directly working with documents within MongoDB. In your project, create a
7977 folder named ``Models``. In the ``Models`` folder, create a new file named
8078 ``MongoDBSettings.cs``. In this file, add the following code:
@@ -91,7 +89,7 @@ the data model for your RESTful API.
9189
9290 The data that will be stored in the class fields defined in the
9391 ``MongoDBSettings`` class is found in the projects' ``appsettings.json``
94- file. Open this file and add the following:
92+ file. Open this file and add the following configuration :
9593
9694 .. code-block:: json
9795 :copyable: true
@@ -105,17 +103,16 @@ the data model for your RESTful API.
105103 },
106104 "AllowedHosts": "*",
107105 "MongoDB": {
108- "ConnectionURI": "ATLAS_URI_HERE ",
106+ "ConnectionURI": "<Atlas connection string> ",
109107 "DatabaseName": "sample_mflix",
110108 "CollectionName": "playlist"
111109 }
112110 }
113111
114- Note the ``MongoDB`` field. This tutorial uses the ``sample_mflix``
115- database and the ``playlist`` collection. Replace the ``ATLAS_URI_HERE``
116- placeholder with your MongoDB Atlas connection string. For more
117- information on how to find your connection string, see the
118- :ref:`csharp-quickstart` guide.
112+ This tutorial uses the ``sample_mflix`` database and the ``playlist``
113+ collection. Replace the ``<Atlas connection string>`` placeholder with
114+ your MongoDB Atlas connection string. For more information on how to find
115+ your connection string, see the :atlas:`Connect to Your Cluster </connect-to-your-cluster>` tutorial.
119116
120117 .. step:: Create the service
121118
@@ -128,31 +125,26 @@ the data model for your RESTful API.
128125 :dedent:
129126
130127 The preceding code defines a class named ``MongoDBService`` that includes
131- empty asynchronous functions. In this tutorial, you will add code to these
132- functions as you create your endpoints. The passed settings from the
133- ``appsettings.json`` file are set to veriables .
128+ empty asynchronous functions. Throughout this tutorial, you add code to these
129+ functions as you create your endpoints. The settings you configured in the
130+ ``appsettings.json`` file are set to variables .
134131
135132 .. step:: Connect the service to the application
136133
137134 Open the ``Program.cs`` file and add the following code to the top of the file:
138135
139- .. code-block:: csharp
140- :copyable: true
141-
142- using MongoExample.Models;
143- using MongoExample.Services;
144-
145- var builder = WebApplication.CreateBuilder(args);
146-
147- builder.Services.Configure<MongoDBSettings>(builder.Configuration.GetSection("MongoDB"));
148- builder.Services.AddSingleton<MongoDBService>();
136+ .. literalinclude:: /includes/fundamentals/code-examples/restful-api-tutorial/MongoDBExampleProgram.cs
137+ :language: csharp
138+ :dedent:
139+ :start-after: start-program-setup
140+ :end-before: end-program-setup
149141
150- In the preceding code, the ``GetSection`` function pulls your settings
142+ In the preceding code, the ``GetSection() `` function pulls your settings
151143 from the ``MongoDB`` field in the ``appsettings.json`` file.
152144
153145 .. tip::
154146
155- If your boilerplate code already has the ``builder`` variable, don't add it twice.
147+ If the template code already has the ``builder`` variable, don't add it twice.
156148
157149 .. step:: Create the document model
158150
@@ -179,7 +171,7 @@ the data model for your RESTful API.
179171 be ``username`` in C#, in JSON, and in MongoDB.
180172
181173You now have a MongoDB service and document model for your collection to work
182- with for .NET Core.
174+ with .NET Core.
183175
184176Build CRUD Endpoints
185177--------------------
@@ -295,7 +287,7 @@ service.
295287 :end-before: end-put
296288 :dedent:
297289
298- .. step:: Delete data using the DELETE endpoint
290+ .. step:: Delete data by using the DELETE endpoint
299291
300292 Go to ``Services/MongoDBService.cs`` and update the ``DeleteAsync`` function to
301293 use the following code:
@@ -325,9 +317,9 @@ Test Your API Endpoints
325317-----------------------
326318
327319With the endpoints created, you can test them using the Swagger UI that is
328- built-in to the boilerplate .NET Core application. To do this, go to
329- ``Program.cs`` file and remove any code from the template project related to
330- ``WeatherForecast`` and similar . Update the file to include the following code:
320+ included with the template .NET Core application. To do this, go to the
321+ ``Program.cs`` file and remove any code from the template project related to the
322+ ``WeatherForecast`` class . Update the file to include the following code:
331323
332324.. literalinclude:: /includes/fundamentals/code-examples/restful-api-tutorial/MongoDBExampleProgram.cs
333325 :language: csharp
@@ -345,17 +337,18 @@ Execute the following command to run your application:
345337
346338After the application starts, open your browser and go to your configured
347339localhost URL to access the Swagger UI, for example
348- ``http://localhost:5000/swagger``. The Swagger UI looks like the following:
340+ ``http://localhost:5000/swagger``. The following image shows how the Swagger UI
341+ appears:
349342
350343.. figure:: /includes/figures/restful-api-tutorial-swagger-ui.jpg
351344 :alt: Swagger UI
352345 :align: center
353346
354347 The Swagger UI for the RESTful API.
355348
356- You can test the application by clicking the `` Try it out` ` button on each
349+ You can test the application by clicking the :guilabel:` Try it out` button on each
357350endpoint. To get started, go to the ``/api/playlists`` ``POST`` endpoint
358- to add some data to the database. Add the following as dummy data:
351+ to add some data to the database. Add the following sample data:
359352
360353.. code-block:: json
361354 :copyable: true
0 commit comments