# Http\_server vs threaded\_httpd

**URL:** <https://swi-prolog.discourse.group/t/http-server-vs-threaded-httpd/1587>\
**Category:** Help!\
**Created:** [December 8, 2019, 6:31pm UTC](https://swi-prolog.discourse.group/t/http-server-vs-threaded-httpd/1587 "2019-12-08T18:31:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [December 8, 2019, 6:31pm UTC](https://swi-prolog.discourse.group/t/http-server-vs-threaded-httpd/1587/1 "2019-12-08T18:31:11Z")

</div>

The documentation for [the HTTP server libraries](https://www.swi-prolog.org/pldoc/man?section=httpserver) has `use_module(library(http/http_server))` but the documentation for [Threaded HTTP Server](https://www.swi-prolog.org/pldoc/doc/_SWI_/library/http/thread_httpd.pl) says that `http/thread_httpd` “defines the HTTP server frontend of choice”.

Are the references to `http/http_server` merely left-overs, or are there reasons for sometimes preferring it? (E.g., perhaps it’s better for debugging?)

Also, it would be nice if [joeblog’s tutorial](https://swi-prolog.discourse.group/t/yet-another-web-applications-tutorial/566) and [Annie Ogborn’s tutorial](http://www.pathwayslms.com/swipltuts/html/index.html) were referenced.

(People don’t necessarily follow the organization of the documentation; I tend to use Google search to find things, so I sometimes read the documentation from back to front. This, of course, is my fault; so feel free to ignore my comments about how the documentation is organized.)

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [December 9, 2019, 9:31am UTC](https://swi-prolog.discourse.group/t/http-server-vs-threaded-httpd/1587/2 "2019-12-09T09:31:40Z")

</div>

> [@peter.ludemann](#):
>
> Are the references to `http/http_server` merely left-overs, or are there reasons for sometimes preferring it? (E.g., perhaps it’s better for debugging?)

No. In fact, `http/http_server` is a more recent library that merely combines the typical HTTP libraries just about any server needs. The idea of a common request handling system and three controlling libraries is outdated, the threaded server now being the only sensible controlling library.

So, new code should use `http/http_server`, unless you want some special setup that requires you to replace one of the components. In that case you can still profit from the modular design.

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [December 10, 2019, 3:31am UTC](https://swi-prolog.discourse.group/t/http-server-vs-threaded-httpd/1587/3 "2019-12-10T03:31:09Z")

</div>

Is it correct to infer that `http_files:http_reply_from_file` should be replaced by `http_dispatch:http_reply_file` because the former doesn’t appear in the export list from `http/http_server`?

(A few tutorials should probably be updated …)

---

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [December 10, 2019, 5:01am UTC](https://swi-prolog.discourse.group/t/http-server-vs-threaded-httpd/1587/4 "2019-12-10T05:01:57Z")

</div>

> [@peter.ludemann](#):
>
> (A few tutorials should probably be updated …)

… and I should probably drink less coffee and do more sports, and yet, here we are 😉

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [December 10, 2019, 7:12am UTC](https://swi-prolog.discourse.group/t/http-server-vs-threaded-httpd/1587/5 "2019-12-10T07:12:20Z")

</div>

If I ever get my toy server written, I’ll try to turn it into a tutorial …

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [December 10, 2019, 8:29am UTC](https://swi-prolog.discourse.group/t/http-server-vs-threaded-httpd/1587/6 "2019-12-10T08:29:22Z")

</div>

> [@peter.ludemann](#):
>
> `http_reply_from_file`

I assume you refer to `http_reply_from_files` (with s)? That is not part of the `http_server` library. Perhaps it should be, but it comes with stuff such as icons to reply directory indexes and thus it isn’t nicely minimal. Replying files is also not really the primary point of the SWI-Prolog server. For example, `nginx` does this better 🙂

If you need it, just add

```
:- use_module(library(http/http_files)).

```

The idea behind the `http_server` library is that it has an easier to remember name, avoids the need for including about 5 files to get a basic server and hides all the internal and deprecated interfaces. If you need more than the real basics you have to add additional libraries (e.g., the above, sessions, authentication, etc.)

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [December 10, 2019, 10:45pm UTC](https://swi-prolog.discourse.group/t/http-server-vs-threaded-httpd/1587/7 "2019-12-10T22:45:05Z")

</div>

`http_reply_from_files/3` (with an “s”) seems to be a more general wrapper on `http_reply_file/3`, which is why I’m surprised that the latter is exported from `http/http_server`.

I’ll try to make a PR with some suggested changes to the http documentation …

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [December 11, 2019, 8:34am UTC](https://swi-prolog.discourse.group/t/http-server-vs-threaded-httpd/1587/8 "2019-12-11T08:34:40Z")

</div>

> [@peter.ludemann](#):
>
> `http_reply_from_files/3` (with an “s”) seems to be a more general wrapper on `http_reply_file/3`

I fear these things always remain a bit arbitrary. The reasoning is partly technical, as in `http_reply_file/3` is part of the http\_dispatch library, which is part of the server wrapper. It is also pretty generic and basic functionality. `http_reply_from_files/3` is in a different library, does a lot of stuff you may (not) want and has dependencies on (icon) files that make deployment of runtime systems more complicated.

So, I think leaving it out of the core makes some sense, but if it is widely felt it should be in I can accept that as well. After all, many servers require it if they implement a web server aiming at the browser to serve CSS and javaScript. But … API servers (JSON I/O) typically do not need it and that might be an important application area for (SWI-)Prolog. I have little clue how many HTTP servers have been written in SWI-Prolog and what they do …
