vlingo / xoom-http

The VLINGO XOOM platform SDK for Reactive, scalable, high-throughput, and resilient HTTP server supporting RESTful services running on XOOM LATTICE and XOOM ACTORS.
https://vlingo.io
Mozilla Public License 2.0
52 stars 16 forks source link

ResourceBuilder should treat trailing slash optional #73

Closed hurelhuyag closed 3 years ago

hurelhuyag commented 3 years ago

I believe that trailing slash "/" character should be optional in every request URL. For instance below example URL should treated same.

http://localhost:18080/veterinarians/{id}/
http://localhost:18080/veterinarians/{id}

Currently if I use route like below snippet and call this endpoint with http://localhost:18080/veterinarians/abc/. this::veterinarian method receiving variable id=abc/. It must be id=abc (without trailing slash)

  @Override
  public Resource<?> routes() {
     return resource("VeterinarianResource",
        io.vlingo.http.resource.ResourceBuilder.get("/veterinarians/{id}")
            .param(String.class)
            .handle(this::veterinarian)
     );
  }
VaughnVernon commented 3 years ago

@hurelhuyag We support the Google interpretation of this. The trailing / indicates a directory, and as such, we first attempt to serve the default content for a directory, namely index.html. If the default resource is not there then the response is a 404.

https://developers.google.com/search/blog/2010/04/to-slash-or-not-to-slash

If you don't want this behavior then please don't place a / at the end of a URL. Besides, if the ending / follows a static file resource, or any other logical resource such as /resources/{id}/ rather than /resources/{id}, what would be the purpose?

Another way to think about this is that if your server and client use hypermedia (HATEOS) then you should never have to hardcode any URL except for the initial root, which is minted. From there every next request should be guided by response headers and/or response entity content. This means that the server will provide hypermedia guidance according to its own rules.

hurelhuyag commented 3 years ago

@VaughnVernon Ok. Then which one is correct for our use case, http://localhost:18080/veterinarians or http://localhost:18080/veterinarians/?

VaughnVernon commented 3 years ago

(1) Assuming that http://localhost:18080/veterinarians is meant to be a resource that is a collection of all individual veterinarian resources, then it is the correct URI.

(2) This URL http://localhost:18080/veterinarians/ would indicate that there is a directory named veterinarians, and we would attempt to read the index.html from that directory. That I am sure would fail with a 404.

To make another point about 1, any veterinarian resources in the response could/should have a URI for each one. In that way, you never have to build your own URI when making requests back to the server. Also, a further step to enable full hypermedia, your responses could even include request lines, such as GET ..., PATCH ..., PUT ..., and DELETE ....

Note also that such request lines would be provided as K-V pairs. For example:

After a successful query, other options could be provided:

hurelhuyag commented 3 years ago

Ok. I remembered something from xoom-starter. According to that rule, This uneditable trailing slash must be eliminated. Right?

Screenshot from 2021-03-16 11-45-40

VaughnVernon commented 3 years ago

Ok. I remembered something from xoom-starter. According to that rule, This uneditable trailing slash must be eliminated. Right?

Yes, I agree. I have asked numerous times for that change. I thought it had already been made. Perhaps @danilo-ambrosio has already made that change but not built the new binary artifact.

Would you please check and see if the change has been made? If not, please attempt to fix it and request @abdullahcalisir12 to review. Otherwise if it seems too difficult, please ask @abdullahcalisir12 to make the change.

VaughnVernon commented 3 years ago

The URL editing issue was fixed.