Search code examples
resthttp-status-code-400

Throwing http 400 for missing Query param and query param with # character


I have built a rest api and I am facing a problem to tackle the invalid requests.

I need to throw HTTP 400 BAD request in the http response, for the following requests:

orders/{orders}/order_file.{format}

This is the uri that I am using.

If clients key in the url as orders//order_file.json I should be able to throw http 400 error.

If clients key in the url as orders/234#/order_file.json I should be able to throw the same http 400 error.

Instead The control is not getting inside the uri handlers for the above 2 scenarios.


Solution

  • The path

    orders//order_file.json
    

    is probably interpreted as

    orders/order_file.json
    

    If you have no rule to match such a path, you will get a 404 Not Found.

    The path

    orders/234#/order_file.json
    

    has a real path orders/234 and a fragment /order_file.json. Again, if you don't have a rule that matches orders/234, you will get a 404 Not Found.