Skip to content
Graham Chiu edited this page Feb 20, 2020 · 2 revisions

Welcome to the rebol-httpd wiki!

Simple Example

Rebol [
    title: "Demo Usage"
    Notes: {
        check the request/action. If it matches a request of the web root, then deliver the index.html
        If you want to add cookies etc, then you'll have to currently modify the build-header function
        in the httpd.

        Currently you can use `render` to send text to the client.  This sets the http code to 200.
        But it would be good if we had options to also set header values
        eg.  set-cookie, and CORS.
    }
]

import <httpd>

srv: open [
    scheme: 'httpd 8888 
    [
        probe request/action
        if request/action = "GET /" [
            response/content: to text! lib/read %index.html
            response/length: length-of response/content
        ]
        probe response
    ]
] 
    
wait [srv]

or more simply

srv: open [
    scheme: 'httpd 8888 
    [
        probe request/action
        if request/action = "GET /" [
            render to text! lib/read %index.html
        ]
        probe response
    ]
] 
Clone this wiki locally