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?
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.
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:
- 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.
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).