Swagger Generated URL Questtion
-
I have an Asp.Net MVC API with this controller :
namespace ApiDemo.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class UsersController : ControllerBase
{
[HttpGet("{id}/{name}/{birthDate}/{isAlive}/{presNo}")]
public IActionResult Get(int id, string name, DateTime birthDate, bool isAlive, int presNo)
{
return StatusCode(200);
}
}
}When I call this Swagger generates this Request URL:
https:// localhost:7062/api/Users/Get/12345/Rutherford%20Birchard%20Hayes%20/1822-10-04%205%3A13%3A22/false/19
I don't understand the instances of '%20B' or '%3A22'. They are not always the same. What are these? Where are they coming from?
In theory, theory and practice are the same. But in practice, they never are.” If it's not broken, fix it until it is. Everything makes sense in someone's mind.
-
I have an Asp.Net MVC API with this controller :
namespace ApiDemo.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class UsersController : ControllerBase
{
[HttpGet("{id}/{name}/{birthDate}/{isAlive}/{presNo}")]
public IActionResult Get(int id, string name, DateTime birthDate, bool isAlive, int presNo)
{
return StatusCode(200);
}
}
}When I call this Swagger generates this Request URL:
https:// localhost:7062/api/Users/Get/12345/Rutherford%20Birchard%20Hayes%20/1822-10-04%205%3A13%3A22/false/19
I don't understand the instances of '%20B' or '%3A22'. They are not always the same. What are these? Where are they coming from?
In theory, theory and practice are the same. But in practice, they never are.” If it's not broken, fix it until it is. Everything makes sense in someone's mind.
It's
%20
, not %20B. The %20 is an encoded space character. The same is true for%3A
, not %3A22. The %3A is a colon. Encoding is required because certain characters are illegal in URLs, like a space or :, unless specified in certain places. For example, a colon is only legal after the protocol and between the hostname and port number. So, your unencoded URL is:https://localhost:7062/api/Users/Get/12345/Rutherford Birchard Hayes /1822-10-04 5:13:22/false/19
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak
-
It's
%20
, not %20B. The %20 is an encoded space character. The same is true for%3A
, not %3A22. The %3A is a colon. Encoding is required because certain characters are illegal in URLs, like a space or :, unless specified in certain places. For example, a colon is only legal after the protocol and between the hostname and port number. So, your unencoded URL is:https://localhost:7062/api/Users/Get/12345/Rutherford Birchard Hayes /1822-10-04 5:13:22/false/19
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak
OK, so here's another from the same api call:
https:// localhost:7062/api/Users/Get/123/Jack%20Jones/1985-04-16%2012%3A34%3A56/true/16
So how would a client like, say for example a console app, call this? Would the app have to format the URL to convert spaces & colons to look like that?? Thanks!
In theory, theory and practice are the same. But in practice, they never are.” If it's not broken, fix it until it is. Everything makes sense in someone's mind.
-
OK, so here's another from the same api call:
https:// localhost:7062/api/Users/Get/123/Jack%20Jones/1985-04-16%2012%3A34%3A56/true/16
So how would a client like, say for example a console app, call this? Would the app have to format the URL to convert spaces & colons to look like that?? Thanks!
In theory, theory and practice are the same. But in practice, they never are.” If it's not broken, fix it until it is. Everything makes sense in someone's mind.
Yes! If you're going to use URLs, no matter what type of app you're writing, you must obey the rules of URLs! WebUtility.UrlEncode(String) Method (System.Net) | Microsoft Learn[^]
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak
-
Yes! If you're going to use URLs, no matter what type of app you're writing, you must obey the rules of URLs! WebUtility.UrlEncode(String) Method (System.Net) | Microsoft Learn[^]
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak
Thanks!
In theory, theory and practice are the same. But in practice, they never are.” If it's not broken, fix it until it is. Everything makes sense in someone's mind.