Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

So I've thought of creating a web application in either Lisp or another functional language and was thinking of embedding the web server into the application (have my application handle the HTTP requests). I don't see any issues with that, however, I'm new to creating web applications (and in the grand scheme of things, programming as well). Is there any drawbacks to handling HTTP requests within your program instead of using a web server? Are there any benefits?

share|improve this question
    
This question reminds me of Node.js, a project that aims to make JavaScript web applications handle their own HTTP connections. Granted, the author of that project doesn't recommend doing so because there are still bugs (presumably jeopardizing security). Just goes to show that handling your own HTTP requests is non-trivial. –  Adam Paynter Mar 14 '11 at 12:04

3 Answers 3

up vote 4 down vote accepted

They major disadvantage of handling your own HTTP requests instead of using an existing web server to server your application is the countless hours of development time that has gone into building web servers that can handle HTTP requests faster and more securely than anything you are likely to code on your own. If you are worried about overhead, you can always try a lightweight http server like Lighttpd or nginx, and server you applications, LISP or whatever, using FastCGI, or a module specific to your language (wsgi for Python, etc).

Or you could always use a Lighttpd or NGinx for your static content and proxy requests for dynamic content to your application or an application server appropriate to your application.

share|improve this answer
    
+1 Not only will using Apache, IIS, etc save dev time at the start of the project, but you can upgrade the web server later on for "free" features. Plus you don't have to maintain it, it reduces complexity, and on and on.. –  Ryan Hayes Mar 14 '11 at 13:05

Before you can really answer that question properly, you have to consider what the demands on the web handler are, and what are the types of interactions you are doing? The set of pros/cons can be different depending on what you are doing:

  • Full Web Application: use an external web server. The external web server will be optimized to handle your non-application requests for static content (i.e. the images, style-sheets, JavaScript, and static HTML pages). Using a good web framework will make building the web application a lot smoother.
  • Just a couple Web Services: It's a draw here. With no static resources to serve up, it's a matter of how much you need to scale. The more concurrent requests you anticipate, the more it pushes you toward the external web server. The key reason is that external web servers are designed to work with load balancing and other approaches to sharing the work load.
  • Point to point application protocol: Embedded server works best. Both the programming effort to handle the few (relatively simple) requests, and the much lower traffic that you are expecting makes embedded servers attractive. You can ignore a large amount of the HTTP specification because you aren't worried about browser caching, and you are focusing only on what you need your application to do.

At the end of the day, an embedded server can be a lot of work. You might be able to embed an open source web server that someone else created to save some time. In fact, that's the approach that Ruby on Rails and Maven based web application projects use to do internal testing. They embed a web server into the build infrastructure to make working on the project a lot easier. The end goal for both of those types of projects, however, is that the product will be deployed on an external web server.

share|improve this answer

The only reason I would embed a web server in my app is if I had a reasonable expectation that it would be installed in an environment where I couldn't expect or require a standalone web server. Keep in mind that your app may have to coexist with other web servers, so it'll have to be configurable (especially the port). Is that configuration something you want to require your users to do?

If this is an experimental app with a limited user base and you want to play, then go ahead! But in "the real world" you would almost never want to do this, as others have mentioned. I have implemented my own web server before, and once you need to do anything more than serve up static pages and a simple app, it quickly turns into a lot of code (even if you ignore security and scalability).

share|improve this answer
    
I didn't even think of having it have to co-exist with other servers. Thanks! –  Jetti Mar 15 '11 at 1:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.