Usually we can send email field data through the body section in the HTTP POST request but in case of GET Request we should pass the email in API URI, so there is some changes need to be done in API URI by sending the Email.
Let us consider the example:
-
- [HttpGet]
- [AllowAnonymous]
- [Route("UserDetails/{Email}")]
- public HttpResponseMessage UserDetails(string Email)
- {
-
- try
- {
-
- return Request.CreateResponse(HttpStatusCode.OK, Email,Configuration.Formatters.JsonFormatter);
- }
- catch (Exception ex)
- {
- return Request.CreateErrorResponse(HttpStatusCode.OK, ex.Message);
- }
- }
From the above code its is clear we have created one API GET Action with Email
Request:
GET: api/Users/UserDetails/Email
Response:
To overcome this issue we should modified the URI.
Instead of sending the request as api/Users/UserDetails/Email we should use api/Users/UserDetails/Email/ , i.e we should add one more forward slash after email.
Request:
GET: api/Users/UserDetails/Email/
Response:
I hope you enjoyed this blog. Your valuable feedback, question, or comments about this blog are always welcomed.