Learn extra at:
app.MapPut("/writer/{authorId:int:min(1)}/books/{depend:int:min(1)}",
(int authorId, int depend) => $"Creator with Id {authorId} has written {depend} books.");
Instance of a route constraint in motion
Lastly, let’s study how we will specify route constraints when passing objects and primitive information sorts (char, int, and so forth.) as parameters. Take into account the next HTTP POST endpoint, which provides a brand new writer and the variety of books authored to a database.
app.MapPost("/authors/{depend:int:min(1)}", (Creator writer, int depend) =>
Outcomes.Okay($"1 new writer file of an writer who has written {depend} " +
$"books has been added to the database...")
);
Let’s invoke this endpoint utilizing Postman. We’ll ship the next JSON information for our new writer within the physique of the request.
{
"authorId": "1",
"firstName": "Joydip",
"lastName": "Kanjilal",
"tackle": "Hyderabad, India",
"e-mail": "joydipkanjilal@yahoo.com",
"telephone": "1234567890"
}
Our route constraint requires us additionally to specify the depend of books written by the writer within the URL. Additional, it requires that the depend be a minimal integer worth of 1. Determine 1 exhibits the output in Postman after we move a depend of 5.