Skip to content

Commit e251611

Browse files
change to use async handlers and format
1 parent 737f563 commit e251611

32 files changed

+429
-397
lines changed

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

+21-21
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ using Application = Nitric.Sdk.Nitric;
2121

2222
var api = Application.Api("main");
2323

24-
api.Delete("/hello/:name", context => {
25-
var name = context.Req.PathParams["name"];
24+
api.Delete("/hello/:name", async (ctx) => {
25+
var name = ctx.Req.PathParams["name"];
2626

27-
context.Res.Text($"Deleting {name}!");
27+
ctx.Res.Text($"Deleting {name}!");
2828

29-
return context;
29+
return ctx;
3030
});
3131

3232
Application.Run();
@@ -60,12 +60,12 @@ using Application = Nitric.Sdk.Nitric;
6060

6161
var api = Application.Api("main");
6262

63-
api.Delete("/hello/:name", context => {
64-
var name = context.Req.PathParams["name"];
63+
api.Delete("/hello/:name", async (ctx) => {
64+
var name = ctx.Req.PathParams["name"];
6565

66-
context.Res.Text($"Deleting {name}!");
66+
ctx.Res.Text($"Deleting {name}!");
6767

68-
return context;
68+
return ctx;
6969
});
7070

7171
Application.Run();
@@ -83,27 +83,27 @@ var api = Application.Api("main");
8383

8484
api.Delete("/hello/:userId",
8585
new Middleware<HttpContext>[] {
86-
(context, next) => {
87-
var user = context.Req.PathParams["userId"];
86+
async (ctx, next) => {
87+
var user = ctx.Req.PathParams["userId"];
8888

8989
// Validate the user identity
9090
if (user != "1234")
9191
{
92-
context.Res.Text($"User {user} is unauthorised");
93-
context.Res.Status = 403;
92+
ctx.Res.Text($"User {user} is unauthorised");
93+
ctx.Res.Status = 403;
9494

9595
// Return prematurely to end the middleware chain.
96-
return context;
96+
return ctx;
9797
}
9898

9999
// Call next to continue the middleware chain.
100-
return next(context);
101-
}, (context, next) => {
102-
var user = context.Req.PathParams["userId"];
100+
return await next(ctx);
101+
}, async (ctx, next) => {
102+
var user = ctx.Req.PathParams["userId"];
103103

104-
context.Res.Text($"Deleting {user}");
104+
ctx.Res.Text($"Deleting {user}");
105105

106-
return next(context);
106+
return await next(ctx);
107107
}
108108
}
109109
);
@@ -121,10 +121,10 @@ using Application = Nitric.Sdk.Nitric;
121121

122122
var api = Application.Api("main");
123123

124-
api.Delete("/hello/:name", context => {
125-
var body = context.Req.Json<Dictionary<string, string>>();
124+
api.Delete("/hello/:name", async (ctx) => {
125+
var body = ctx.Req.Json<Dictionary<string, string>>();
126126
// parse, validate and store the request payload...
127-
return context;
127+
return ctx;
128128
});
129129

130130
Application.Run();

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

+18-18
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ using Application = Nitric.Sdk.Nitric;
2121

2222
var api = Application.Api("main");
2323

24-
api.Get("/hello/:name", context => {
25-
var name = context.Req.PathParams["name"];
24+
api.Get("/hello/:name", async (ctx) => {
25+
var name = ctx.Req.PathParams["name"];
2626

27-
context.Res.Text($"Getting {name}!");
27+
ctx.Res.Text($"Getting {name}!");
2828

29-
return context;
29+
return ctx;
3030
});
3131

3232
Application.Run();
@@ -60,12 +60,12 @@ using Application = Nitric.Sdk.Nitric;
6060

6161
var api = Application.Api("main");
6262

63-
api.Get("/hello/:name", context => {
64-
var name = context.Req.PathParams["name"];
63+
api.Get("/hello/:name", async (ctx) => {
64+
var name = ctx.Req.PathParams["name"];
6565

66-
context.Res.Text($"Getting {name}!");
66+
ctx.Res.Text($"Getting {name}!");
6767

68-
return context;
68+
return ctx;
6969
});
7070

7171
Application.Run();
@@ -83,27 +83,27 @@ var api = Application.Api("main");
8383

8484
api.Get("/hello/:userId",
8585
new Middleware<HttpContext>[] {
86-
(context, next) => {
87-
var user = context.Req.PathParams["userId"];
86+
async (ctx, next) => {
87+
var user = ctx.Req.PathParams["userId"];
8888

8989
// Validate the user identity
9090
if (user != "1234")
9191
{
92-
context.Res.Text($"User {user} is unauthorised");
93-
context.Res.Status = 403;
92+
ctx.Res.Text($"User {user} is unauthorised");
93+
ctx.Res.Status = 403;
9494

9595
// Return prematurely to end the middleware chain.
96-
return context;
96+
return ctx;
9797
}
9898

9999
// Call next to continue the middleware chain.
100-
return next(context);
101-
}, (context, next) => {
102-
var user = context.Req.PathParams["userId"];
100+
return await next(ctx);
101+
}, async (ctx, next) => {
102+
var user = ctx.Req.PathParams["userId"];
103103

104-
context.Res.Text($"Getting {user}");
104+
ctx.Res.Text($"Getting {user}");
105105

106-
return next(context);
106+
return await next(ctx);
107107
}
108108
}
109109
);

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

+21-21
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ using Application = Nitric.Sdk.Nitric;
2121

2222
var api = Application.Api("main");
2323

24-
api.Patch("/hello/:name", context => {
25-
var name = context.Req.PathParams["name"];
24+
api.Patch("/hello/:name", async (ctx) => {
25+
var name = ctx.Req.PathParams["name"];
2626

27-
context.Res.Text($"Patching {name}!");
27+
ctx.Res.Text($"Patching {name}!");
2828

29-
return context;
29+
return ctx;
3030
});
3131

3232
Application.Run();
@@ -60,12 +60,12 @@ using Application = Nitric.Sdk.Nitric;
6060

6161
var api = Application.Api("main");
6262

63-
api.Patch("/hello/:name", context => {
64-
var name = context.Req.PathParams["name"];
63+
api.Patch("/hello/:name", async (ctx) => {
64+
var name = ctx.Req.PathParams["name"];
6565

66-
context.Res.Text($"Patching {name}!");
66+
ctx.Res.Text($"Patching {name}!");
6767

68-
return context;
68+
return ctx;
6969
});
7070

7171
Application.Run();
@@ -83,27 +83,27 @@ var api = Application.Api("main");
8383

8484
api.Patch("/hello/:userId",
8585
new Middleware<HttpContext>[] {
86-
(context, next) => {
87-
var user = context.Req.PathParams["userId"];
86+
async (ctx, next) => {
87+
var user = ctx.Req.PathParams["userId"];
8888

8989
// Validate the user identity
9090
if (user != "1234")
9191
{
92-
context.Res.Text($"User {user} is unauthorised");
93-
context.Res.Status = 403;
92+
ctx.Res.Text($"User {user} is unauthorised");
93+
ctx.Res.Status = 403;
9494

9595
// Return prematurely to end the middleware chain.
96-
return context;
96+
return ctx;
9797
}
9898

9999
// Call next to continue the middleware chain.
100-
return next(context);
101-
}, (context, next) => {
102-
var user = context.Req.PathParams["userId"];
100+
return await next(ctx);
101+
}, async (ctx, next) => {
102+
var user = ctx.Req.PathParams["userId"];
103103

104-
context.Res.Text($"Patching {user}");
104+
ctx.Res.Text($"Patching {user}");
105105

106-
return next(context);
106+
return await next(ctx);
107107
}
108108
}
109109
);
@@ -121,10 +121,10 @@ using System.Collections.Generic;
121121

122122
var api = Application.Api("main");
123123

124-
api.Patch("/hello/:name", context => {
125-
var body = context.Req.Json<Dictionary<string, string>>();
124+
api.Patch("/hello/:name", async (ctx) => {
125+
var body = ctx.Req.Json<Dictionary<string, string>>();
126126
// parse, validate and store the request payload...
127-
return context;
127+
return ctx;
128128
});
129129

130130
Application.Run();

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

+22-22
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ using Application = Nitric.Sdk.Nitric;
2121

2222
var api = Application.Api("main");
2323

24-
api.Post("/hello/:name", context => {
25-
var name = context.Req.PathParams["name"];
24+
api.Post("/hello/:name", async (ctx) => {
25+
var name = ctx.Req.PathParams["name"];
2626

27-
context.Res.Text($"Creating {name}!");
27+
ctx.Res.Text($"Creating {name}!");
2828

29-
return context;
29+
return ctx;
3030
});
3131

3232
Application.Run();
@@ -60,12 +60,12 @@ using Application = Nitric.Sdk.Nitric;
6060

6161
var api = Application.Api("main");
6262

63-
api.Post("/hello/:name", context => {
64-
var name = context.Req.PathParams["name"];
63+
api.Post("/hello/:name", async (ctx) => {
64+
var name = ctx.Req.PathParams["name"];
6565

66-
context.Res.Text($"Creating {name}!");
66+
ctx.Res.Text($"Creating {name}!");
6767

68-
return context;
68+
return ctx;
6969
});
7070

7171
Application.Run();
@@ -83,27 +83,27 @@ var api = Application.Api("main");
8383

8484
api.Post("/hello/:userId",
8585
new Middleware<HttpContext>[] {
86-
(context, next) => {
87-
var user = context.Req.PathParams["userId"];
86+
async (ctx, next) => {
87+
var user = ctx.Req.PathParams["userId"];
8888

8989
// Validate the user identity
9090
if (user != "1234")
9191
{
92-
context.Res.Text($"User {user} is unauthorised");
93-
context.Res.Status = 403;
92+
ctx.Res.Text($"User {user} is unauthorised");
93+
ctx.Res.Status = 403;
9494

95-
// Return prematurely to end the middleware chain.
96-
return context;
95+
// Return prematurely to end the middleware chain.
96+
return ctx;
9797
}
9898

9999
// Call next to continue the middleware chain.
100-
return next(context);
101-
}, (context, next) => {
102-
var user = context.Req.PathParams["userId"];
100+
return await next(ctx);
101+
}, async (ctx, next) => {
102+
var user = ctx.Req.PathParams["userId"];
103103

104-
context.Res.Text($"Creating {user}");
104+
ctx.Res.Text($"Creating {user}");
105105

106-
return next(context);
106+
return await next(ctx);
107107
}
108108
}
109109
);
@@ -121,10 +121,10 @@ using System.Collections.Generic;
121121

122122
var api = Application.Api("main");
123123

124-
api.Post("/hello/:name", context => {
125-
var body = context.Req.Json<Dictionary<string, string>>();
124+
api.Post("/hello/:name", async (ctx) => {
125+
var body = ctx.Req.Json<Dictionary<string, string>>();
126126
// parse, validate and store the request payload...
127-
return context;
127+
return ctx;
128128
});
129129

130130
Application.Run();

0 commit comments

Comments
 (0)