You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/index.md
+24
Original file line number
Diff line number
Diff line change
@@ -37,3 +37,27 @@ Minimal routes by design. Create meaningful low ceremony URLs that execute your
37
37
```csharp
38
38
app.MapGet("/", () =>"Hello World!");
39
39
```
40
+
### Feels familiar
41
+
42
+
Minimal code patterns have been popular in JavaScript and Python web frameworks for a while. Whether you are familiar with Express or Flask, we think you can easily do things you enjoy about those frameworks with minimal APIs as well.
43
+
44
+
**For example**
45
+
46
+
Routes in Express
47
+
```JS
48
+
// GET method route
49
+
app.get('/', function (req, res) {
50
+
res.send('GET request to the homepage')
51
+
})
52
+
53
+
// POST method route
54
+
app.post('/', function (req, res) {
55
+
res.send('POST request to the homepage')
56
+
})
57
+
```
58
+
Routes in minimal APIs
59
+
```csharp
60
+
app.MapGet("/", () =>"GET request to the homepage");
61
+
app.MapPost("/", () =>"POST request to the homepage");
In checklist one, you built simple API where you hardcoded the results to HTTP method.
4
+
In [checklist one](/tutorial/first-steps), you built simple API where you hard coded the results to HTTP method.
5
5
6
6
For example: `app.MapGet("/todo", () => new { Item = "Water plants", Complete = "false" });` has been hard coded to return the JSON results below.
7
7
@@ -12,21 +12,18 @@ For example: `app.MapGet("/todo", () => new { Item = "Water plants", Complete =
12
12
}
13
13
```
14
14
15
-
In checklist 2, you are going to step it up a notch and create something dynamic. Instead of returning a static item that is hardcoded to your route, you are going to be creating to-do list you can update, create new items, mark an item as complete, and delete an item.
16
-
17
-
### Learn checklist Two ✔️
15
+
In checklist 3 we are going to step it up a notch and create something dynamic. Instead of returning a static item that is hardcoded to our route, we are going to be creating to-do list we can update, create new items, mark an item as complete and delete an item.
18
16
19
17
Our to-do APIs is going to:
20
-
21
18
- Create a new item.➕
22
19
- Return a specific item on a list. :leftwards_arrow_with_hook:
23
20
- Update an existing item. :arrows_counterclockwise:
24
21
- Delete an item. ➖
25
22
26
-
Create a class that models the data you want to collect, that is, Data model. The code for your `TodoItem` will go after `app.Run();`
27
23
28
-
**Create a data model**
24
+
Create a class that models the data we want to collect aka Data model. The code for your `TodoItem` will go after `app.Run();`
29
25
26
+
**Create a data model**
30
27
```cs
31
28
classTodoItem
32
29
{
@@ -36,43 +33,34 @@ class TodoItem
36
33
37
34
}
38
35
```
36
+
Now, that we have defined that data we want to collect we need to save it.
39
37
40
-
Now that you've defined the data you want to collect, you need to save it.
38
+
**Store an item**
41
39
42
-
**Store an item**
40
+
To store the items in the to do list we are going need to install the Entity Frameworkcore InMemomry package below.
43
41
44
-
To store the items in the to do list, install the Entity Framework Core InMemomry package as shown below.
42
+
> *What is Entity Framework?* is a code library that enables the transfer of data stored in relational database tables(E.g. SQLite and MySQL, SQL server etc) into objects that are more commonly used in application code.
45
43
46
-
*What is Entity Framework (EF)?* EF is a code library that enables the transfer of data stored in relational database tables (such as, SQLite, MySQL, and SQL Server) into objects that are more commonly used in application code.
Add `using Microsoft.EntityFrameworkCore;` to the top of your `Program.cs` file.
65
53
66
-
Now that you have Entity Framework, you can wire up your code to the data you want to save and query. To do this, create a `TodoDb` class. This class is going to do the following:
54
+
Now, that we have EntityFramework we can now wire up our code to the data we want save and query it. To do this we are going to create a `TodoDb` class. `TodoDb` class is going to do the following:
67
55
68
-
- Expose the`Todos` property from the list of `TodoItem` in the database.
69
-
-`UseInMemoryDatabase` wires the in-memory database storage.This will store data as long the app is running.
56
+
- Expose our`Todos` property from our list of `TodoItem` in the database.
57
+
-`UseInMemoryDatabase` wires the inmemory database storage.This will store data as long the app is running.
70
58
71
-
To set up your in-memory database, add the following code snippets to your code.
59
+
To setup your inmemory database add the following code snippets to our code.
72
60
73
-
**Snippet 1** : Below the `TodoItem`, create a `TodoDb` class:
61
+
**Snippet 1** : Below the `TodoItem` create a `TodoDb` class
`DbContext` represents a connection/session which is used to query and save instances of entities in a database.
87
76
88
-
`DbContext` represents a connection/session, which is used to query and save instances of entities in a database.
89
-
90
-
**Snippet 2** : Before `AddSwaggerGen` services that you configured in the [first tutorial](first-steps.md#interactive-api-docs), add the following code snippet.
77
+
**Snippet 2** : Before `AddSwaggerGen` services we configured in the [first tutorial](https://github.com/LadyNaggaga/minimal-apis-blog/blob/b5e97d3168b0948d8926afbd6dbc883cb32ba21a/Tutorials/Firststeps.md#interactive-api-docs) add the code snippet below.
Go back your browser and navigate to `https://localhost:5001/swagger`. Click on the **GET**`/todos` button and you should see that the list is empty under `Response body`.
90
+
Go back your browser and navigate to `https://localhost:5001/swagger` click on the **GET**`/todos` button and you will see the list is empty under `Response body`.
0 commit comments