I’m writing a http API, and I need a bit more flexibility than I’m used to in asp.net. It’s pretty simple problem I have, and just need some help getting on the right track.
My problem is, that I want to create a response object based on the request. F.x a user can get a xml document when requesting: “myapi/images/5/xml”. Or get it as a json if it had ended with json. I have no problems creating the right response objects. I just need a way to collect all the request in some object, then parse the URL with a regex and create the right response on that.
But how do I collect all requests on a web application?
You probably don’t want to parse the whole URL with a regex. It’d probably be easier to hook into ASP.NET’s routing engine:-
Then your action method can accept a parameter
responseTypefrom the url.I agree with steven’s comment above, though, you should probably get the response type from the request header rather than from the url.