Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Swagger Generated URL Questtion

Swagger Generated URL Questtion

Scheduled Pinned Locked Moved Web Development
asp-netcsharpjsonarchitecturehelp
5 Posts 2 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    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.

    D 1 Reply Last reply
    0
    • K Kevin Marois

      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.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      K 1 Reply Last reply
      0
      • D 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

        K Offline
        K Offline
        Kevin Marois
        wrote on last edited by
        #3

        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.

        D 1 Reply Last reply
        0
        • K Kevin Marois

          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.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          K 1 Reply Last reply
          0
          • D 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

            K Offline
            K Offline
            Kevin Marois
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups