5

I have an ASP.Net 4 website, non MVC, that is Forms Authenticated, and I need to equip it with an API. After googlage, it seems RESTful API would give greatest accessibility.

I already have asynchronous custom HTTP Handler code in place, for some Comet functions. I would like to use async handlers in the API, to ensure the IIS threadpool is not tied up, and to keep performance optimal.

I would like to try to stay REST faithful and use the URI to access and change resources. Are there design guides around for this kind of thing, as it seems like a task that many devs would face?

I am unsure as to whether to use one handler for the API that fires for all HTTP verbs, or one handler per resource type, or multiple handlers derived from a generic async handler. Any guidance would be appreciated.

1 Answer 1

2
+25

In your situation, I'd just make use of Web API. It's easy to integrate with WebForms projects, and it's basically made for doing REST in ASP.NET. While the article doesn't show it, the Web API lets you use Task<> in your controllers, making it nice and async.

If you absolutely insist on keeping any and all ASP.NET MVC components out of your WebForms project—even though they're perfectly compatible with one another—then I don't know what to tell you, because doing it without MVC just seems counterproductive to me; like reinventing the wheel.

Sign up to request clarification or add additional context in comments.

3 Comments

Can I route an API request to a custom HTTP asynchronous handler? I already have some asynch HTTP handlers in place for Comet code, and would like to bring these into the API fold or replace them with API versions. I will take a look at the links this week and add more comments, but thanks for the response.
Well, there's no direct way of routing directly to a IHttpAsyncHandler as far as I know (and believe me, I could easily be wrong here), but there are asynchronous controllers in ASP.NET MVC, which work similarly, and I'm pretty sure you could fire them off from within that framework, if you want to.
Task methods might be enough to get Comet working. Whilst waiting for data, I don't complete the task. If data arrives to go to the client, I complete the task and push to client, and if the timeout is hit, I complete the task with no data. I have some experimenting to do...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.