From a47db5277c1f48ffa4149807e62ce17d3ac9cfdd Mon Sep 17 00:00:00 2001 From: H Masri Date: Fri, 24 Feb 2017 05:59:22 +0800 Subject: [PATCH] {authorId:int} instead of {authorId} (#2822) // its better to use {authorId:int} instead of just {authorId} // wrong {authorId} will produce a 400 error with error message // wrong {authorId:int} will produce a 404 error Since the publish date route is limited to a couple of formats, I assume you're of the type to prefer to control what type of error is shown to the resource user. --- .../samples/sample17.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aspnet/web-api/overview/web-api-routing-and-actions/create-a-rest-api-with-attribute-routing/samples/sample17.cs b/aspnet/web-api/overview/web-api-routing-and-actions/create-a-rest-api-with-attribute-routing/samples/sample17.cs index 93bcb936ca..b55eabf4ae 100644 --- a/aspnet/web-api/overview/web-api-routing-and-actions/create-a-rest-api-with-attribute-routing/samples/sample17.cs +++ b/aspnet/web-api/overview/web-api-routing-and-actions/create-a-rest-api-with-attribute-routing/samples/sample17.cs @@ -1,7 +1,7 @@ -[Route("~api/authors/{authorId}/books")] +[Route("~/api/authors/{authorId:int}/books")] public IQueryable GetBooksByAuthor(int authorId) { return db.Books.Include(b => b.Author) .Where(b => b.AuthorId == authorId) .Select(AsBookDto); -} \ No newline at end of file +}