# Http reply for simple API

**URL:** <https://swi-prolog.discourse.group/t/http-reply-for-simple-api/9508>\
**Category:** General\
**Created:** [February 4, 2026, 2:26am UTC](https://swi-prolog.discourse.group/t/http-reply-for-simple-api/9508 "2026-02-04T02:26:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcculloch](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@mcculloch](https://swi-prolog.discourse.group/u/mcculloch)\
**Post date:** [February 4, 2026, 2:26am UTC](https://swi-prolog.discourse.group/t/http-reply-for-simple-api/9508/1 "2026-02-04T02:26:05Z")

</div>

I’m working on a http server and I can get it to run on a Linux Mint machine as a daemon. The routes appear to work and I even have a simple route that kills the process. The routes work but the way I am doing the reply to the client tells me the server is sending an empty response and I think I misunderstand the doc section on creating a http reply. I’m not sending a header, and I’m pretty sure that’s the problem but there’s no html involved and I was wondering how I would reply a simple string.

The examples in the docs always assume html is involved. What would a reply clause look like if I just want to return a string?

---

<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:** [February 4, 2026, 8:30am UTC](https://swi-prolog.discourse.group/t/http-reply-for-simple-api/9508/2 "2026-02-04T08:30:54Z")

</div>

To reply a simple string just use the CGI-style API:

```prolog
handle(Request) :-
    format('Content-type: text/plain~n~n'),
    format('Hello World!~n').

```

Using that you can reply to just about anything. There are high level commands for replying files, directory indexes, HTML, JSON and various status messages (404, etc.)

---

<div class="post-metadata">

**Author:** ![drspro](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/drspro/32/3509_2.png) [@drspro](https://swi-prolog.discourse.group/u/drspro)\
**Post date:** [February 4, 2026, 8:35am UTC](https://swi-prolog.discourse.group/t/http-reply-for-simple-api/9508/3 "2026-02-04T08:35:58Z")

</div>

I have a swi prolog http server running too. I have something like this , it contains the format content type as well.

```prolog
:- http_handler( root( Fn ), reply_html_with_replacements(Fn), [prefix]).

reply_html_with_replacements( File , Request ):-
  % periodically_data_to_files(),
  atom_concat( 'web/' , File , Fx0 ) ,
  osdir_file( Fx0, Fx ) , 
  exists_file( Fx ) , ! ,
  http_parameters( Request, [], [form_data( Datastr )] ) ,

  format( "Content-type: text/html~n~n" ),
  httpstr_to_mem( Datastr ) ,
  ip_to_mem( Request , Ip_adres_ato ) , ... etc

```

---

<div class="post-metadata">

**Author:** ![mcculloch](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@mcculloch](https://swi-prolog.discourse.group/u/mcculloch)\
**Post date:** [February 4, 2026, 12:36pm UTC](https://swi-prolog.discourse.group/t/http-reply-for-simple-api/9508/4 "2026-02-04T12:36:28Z")

</div>

Thanks! I didn’t have a Content-type line or the following blank line.

---

<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:** [February 5, 2026, 9:02am UTC](https://swi-prolog.discourse.group/t/http-reply-for-simple-api/9508/5 "2026-02-05T09:02:12Z")

</div>

Split this topic on February 5, 2026, 9:02am UTC

A post was split to a new topic: [HTTP DDoS protection](https://swi-prolog.discourse.group/t/http-ddos-protection/9509)
