Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 8830190

Browse files
fix references to middleware
1 parent a3fa596 commit 8830190

15 files changed

+143
-109
lines changed

docs/reference/csharp/api/api-delete.mdx

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,53 +71,56 @@ Application.Run();
7171
When multiple functions are provided they will be called as a chain. If one succeeds, it will move on to the next. This allows middleware to be composed into more complex handlers.
7272

7373
```csharp
74-
using Nitric.Sdk;
74+
using Nitric.Sdk.Service;
75+
using Application = Nitric.Sdk.Nitric;
7576

76-
var api = Nitric.Api("main");
77+
var api = Application.Api("main");
7778

7879
api.Delete("/hello/:userId",
79-
(context, next) => {
80-
var user = context.Req.PathParams["userId"];
80+
new Middleware<HttpContext>[] {
81+
(context, next) => {
82+
var user = context.Req.PathParams["userId"];
8183

82-
// Validate the user identity
83-
if (user != "1234")
84-
{
85-
context.Res.Text($"User {user} is unauthorised");
86-
context.Res.Status = 403;
84+
// Validate the user identity
85+
if (user != "1234")
86+
{
87+
context.Res.Text($"User {user} is unauthorised");
88+
context.Res.Status = 403;
8789

88-
// Return prematurely to end the middleware chain.
89-
return context;
90-
}
90+
// Return prematurely to end the middleware chain.
91+
return context;
92+
}
9193

92-
// Call next to continue the middleware chain.
93-
return next(context);
94-
}, (context, next) => {
95-
var user = context.Req.PathParams["userId"];
94+
// Call next to continue the middleware chain.
95+
return next(context);
96+
}, (context, next) => {
97+
var user = context.Req.PathParams["userId"];
9698

97-
context.Res.Text($"Deleting {user}");
99+
context.Res.Text($"Deleting {user}");
98100

99-
return next(context);
101+
return next(context);
102+
}
100103
}
101104
);
102105

103-
Nitric.Run();
106+
Application.Run();
104107
```
105108

106109
### Access the request body
107110

108111
The DELETE request body is accessible from the `context.Req` object.
109112

110113
```csharp
111-
using Nitric.Sdk;
112114
using System.Collections.Generic;
115+
using Application = Nitric.Sdk.Nitric;
113116

114-
var api = Nitric.Api("main");
117+
var api = Application.Api("main");
115118

116119
api.Delete("/hello/:name", context => {
117120
var body = context.Req.Json<Dictionary<string, string>>();
118121
// parse, validate and store the request payload...
119122
return context;
120123
});
121124

122-
Nitric.Run();
125+
Application.Run();
123126
```

docs/reference/csharp/api/api-get.mdx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,32 +71,35 @@ Application.Run();
7171
When multiple functions are provided they will be called as a chain. If one succeeds, it will move on to the next. This allows middleware to be composed into more complex handlers.
7272

7373
```csharp
74+
using Nitric.Sdk.Service;
7475
using Application = Nitric.Sdk.Nitric;
7576

7677
var api = Application.Api("main");
7778

7879
api.Get("/hello/:userId",
79-
(context, next) => {
80-
var user = context.Req.PathParams["userId"];
80+
new Middleware<HttpContext>[] {
81+
(context, next) => {
82+
var user = context.Req.PathParams["userId"];
8183

82-
// Validate the user identity
83-
if (user != "1234")
84-
{
85-
context.Res.Text($"User {user} is unauthorised");
86-
context.Res.Status = 403;
84+
// Validate the user identity
85+
if (user != "1234")
86+
{
87+
context.Res.Text($"User {user} is unauthorised");
88+
context.Res.Status = 403;
8789

88-
// Return prematurely to end the middleware chain.
89-
return context;
90-
}
90+
// Return prematurely to end the middleware chain.
91+
return context;
92+
}
9193

92-
// Call next to continue the middleware chain.
93-
return next(context);
94-
}, (context, next) => {
95-
var user = context.Req.PathParams["userId"];
94+
// Call next to continue the middleware chain.
95+
return next(context);
96+
}, (context, next) => {
97+
var user = context.Req.PathParams["userId"];
9698

97-
context.Res.Text($"Getting {user}");
99+
context.Res.Text($"Getting {user}");
98100

99-
return next(context);
101+
return next(context);
102+
}
100103
}
101104
);
102105

docs/reference/csharp/api/api-patch.mdx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,32 +71,35 @@ Application.Run();
7171
When multiple functions are provided they will be called as a chain. If one succeeds, it will move on to the next. This allows middleware to be composed into more complex handlers.
7272

7373
```csharp
74+
using Nitric.Sdk.Service;
7475
using Application = Nitric.Sdk.Nitric;
7576

7677
var api = Application.Api("main");
7778

7879
api.Patch("/hello/:userId",
79-
(context, next) => {
80-
var user = context.Req.PathParams["userId"];
80+
new Middleware<HttpContext>[] {
81+
(context, next) => {
82+
var user = context.Req.PathParams["userId"];
8183

82-
// Validate the user identity
83-
if (user != "1234")
84-
{
85-
context.Res.Text($"User {user} is unauthorised");
86-
context.Res.Status = 403;
84+
// Validate the user identity
85+
if (user != "1234")
86+
{
87+
context.Res.Text($"User {user} is unauthorised");
88+
context.Res.Status = 403;
8789

88-
// Return prematurely to end the middleware chain.
89-
return context;
90-
}
90+
// Return prematurely to end the middleware chain.
91+
return context;
92+
}
9193

92-
// Call next to continue the middleware chain.
93-
return next(context);
94-
}, (context, next) => {
95-
var user = context.Req.PathParams["userId"];
94+
// Call next to continue the middleware chain.
95+
return next(context);
96+
}, (context, next) => {
97+
var user = context.Req.PathParams["userId"];
9698

97-
context.Res.Text($"Patching {user}");
99+
context.Res.Text($"Patching {user}");
98100

99-
return next(context);
101+
return next(context);
102+
}
100103
}
101104
);
102105

docs/reference/csharp/api/api-post.mdx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,32 +71,35 @@ Application.Run();
7171
When multiple functions are provided they will be called as a chain. If one succeeds, it will move on to the next. This allows middleware to be composed into more complex handlers.
7272

7373
```csharp
74+
using Nitric.Sdk.Service;
7475
using Application = Nitric.Sdk.Nitric;
7576

7677
var api = Application.Api("main");
7778

7879
api.Post("/hello/:userId",
79-
(context, next) => {
80-
var user = context.Req.PathParams["userId"];
80+
new Middleware<HttpContext>[] {
81+
(context, next) => {
82+
var user = context.Req.PathParams["userId"];
8183

82-
// Validate the user identity
83-
if (user != "1234")
84-
{
85-
context.Res.Text($"User {user} is unauthorised");
86-
context.Res.Status = 403;
84+
// Validate the user identity
85+
if (user != "1234")
86+
{
87+
context.Res.Text($"User {user} is unauthorised");
88+
context.Res.Status = 403;
8789

88-
// Return prematurely to end the middleware chain.
89-
return context;
90-
}
90+
// Return prematurely to end the middleware chain.
91+
return context;
92+
}
9193

92-
// Call next to continue the middleware chain.
93-
return next(context);
94-
}, (context, next) => {
95-
var user = context.Req.PathParams["userId"];
94+
// Call next to continue the middleware chain.
95+
return next(context);
96+
}, (context, next) => {
97+
var user = context.Req.PathParams["userId"];
9698

97-
context.Res.Text($"Creating {user}");
99+
context.Res.Text($"Creating {user}");
98100

99-
return next(context);
101+
return next(context);
102+
}
100103
}
101104
);
102105

docs/reference/csharp/api/api-put.mdx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,32 +71,35 @@ Application.Run();
7171
When multiple functions are provided they will be called as a chain. If one succeeds, it will move on to the next. This allows middleware to be composed into more complex handlers.
7272

7373
```csharp
74+
using Nitric.Sdk.Service;
7475
using Application = Nitric.Sdk.Nitric;
7576

7677
var api = Application.Api("main");
7778

7879
api.Put("/hello/:userId",
79-
(context, next) => {
80-
var user = context.Req.PathParams["userId"];
80+
new Middleware<HttpContext>[] {
81+
(context, next) => {
82+
var user = context.Req.PathParams["userId"];
8183

82-
// Validate the user identity
83-
if (user != "1234")
84-
{
85-
context.Res.Text($"User {user} is unauthorised");
86-
context.Res.Status = 403;
84+
// Validate the user identity
85+
if (user != "1234")
86+
{
87+
context.Res.Text($"User {user} is unauthorised");
88+
context.Res.Status = 403;
8789

88-
// Return prematurely to end the middleware chain.
89-
return context;
90-
}
90+
// Return prematurely to end the middleware chain.
91+
return context;
92+
}
9193

92-
// Call next to continue the middleware chain.
93-
return next(context);
94-
}, (context, next) => {
95-
var user = context.Req.PathParams["userId"];
94+
// Call next to continue the middleware chain.
95+
return next(context);
96+
}, (context, next) => {
97+
var user = context.Req.PathParams["userId"];
9698

97-
context.Res.Text($"Updating {user}");
99+
context.Res.Text($"Updating {user}");
98100

99-
return next(context);
101+
return next(context);
102+
}
100103
}
101104
);
102105

docs/reference/csharp/api/api-route-all.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ Application.Run();
8383
When multiple functions are provided they will be called as a chain. If one succeeds, it will move on to the next. This allows middleware to be composed into more complex handlers.
8484

8585
```csharp
86+
using Nitric.Sdk.Service;
8687
using Application = Nitric.Sdk.Nitric;
8788

8889
var route = Application.Api("main").Route("/customers");
8990

90-
route.All((context, next) => {
91+
route.All(new Middleware<HttpContext>[] {
92+
(context, next) => {
9193
var user = context.Req.PathParams["userId"];
9294

9395
// Validate the user identity
@@ -109,7 +111,7 @@ route.All((context, next) => {
109111

110112
return next(context);
111113
}
112-
);
114+
});
113115

114116
Application.Run();
115117
```

docs/reference/csharp/api/api-route-delete.mdx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ Application.Run();
6868
When multiple functions are provided they will be called as a chain. If one succeeds, it will move on to the next. This allows middleware to be composed into more complex handlers.
6969

7070
```csharp
71+
using Nitric.Sdk.Service;
7172
using Application = Nitric.Sdk.Nitric;
7273

73-
var route = Nitric.Api("main").Route("/customers/:userId");
74+
var route = Application.Api("main").Route("/customers/:userId");
7475

75-
route.Delete((context, next) => {
76+
route.Delete(new Middleware<HttpContext>[] {
77+
(context, next) => {
7678
var user = context.Req.PathParams["userId"];
7779

7880
// Validate the user identity
@@ -94,7 +96,7 @@ route.Delete((context, next) => {
9496

9597
return next(context);
9698
}
97-
);
99+
});
98100

99101
Application.Run();
100102
```

docs/reference/csharp/api/api-route-get.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ Application.Run();
6868
When multiple functions are provided they will be called as a chain. If one succeeds, it will move on to the next. This allows middleware to be composed into more complex handlers.
6969

7070
```csharp
71+
using Nitric.Sdk.Service;
7172
using Application = Nitric.Sdk.Nitric;
7273

7374
var route = Application.Api("main").Route("/customers");
7475

75-
route.Get((context, next) => {
76+
route.Get(new Middleware<HttpContext>[] {
77+
(context, next) => {
7678
var user = context.Req.PathParams["userId"];
7779

7880
// Validate the user identity
@@ -94,7 +96,7 @@ route.Get((context, next) => {
9496

9597
return next(context);
9698
}
97-
);
99+
});
98100

99101
Application.Run();
100102
```

docs/reference/csharp/api/api-route-patch.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ Application.Run();
6868
When multiple functions are provided they will be called as a chain. If one succeeds, it will move on to the next. This allows middleware to be composed into more complex handlers.
6969

7070
```csharp
71+
using Nitric.Sdk.Service;
7172
using Application = Nitric.Sdk.Application;
7273

7374
var route = Application.Api("main").Route("/customers/:userId");
7475

75-
route.Patch((context, next) => {
76+
route.Patch(new Middleware<HttpContext>[] {
77+
(context, next) => {
7678
var user = context.Req.PathParams["userId"];
7779

7880
// Validate the user identity
@@ -94,7 +96,7 @@ route.Patch((context, next) => {
9496

9597
return next(context);
9698
}
97-
);
99+
});
98100

99101
Application.Run();
100102
```

0 commit comments

Comments
 (0)