Skip to content

Instantly share code, notes, and snippets.

@rgchris
Created December 19, 2018 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgchris/fa7de8a11c7a903e3ab7116a90b51994 to your computer and use it in GitHub Desktop.
Save rgchris/fa7de8a11c7a903e3ab7116a90b51994 to your computer and use it in GitHub Desktop.
Small JSON server for Rebol 2
Rebol [
Title: "JSON Server"
Date: 19-Dec-2018
Author: "Christopher Ross-Gill"
]
do http://reb4.me/r/altjson
do http://reb4.me/r/httpd
data: [ ; in lieu of CSV data, from Rebol in Ten Steps
"Bill" billg@ms.com #315-555-1234
"Steve" jobs@apl.com #408-555-4321
"Ted" ted@gw2.com #213-555-1010
]
my-server: open/custom httpd://:8888 [
; default is to return 404
switch probe request/action [
"GET /" [
response/status: 200
response/content: "My Server (<a href='/quit'>Quit</quit>)"
response/type: "text/html"
]
"GET /data" [
response/status: 200
response/content: to-json data
response/type: "application/json"
]
"GET /quit" [
response/status: 200
response/content: "All Done."
response/kill?: yes
]
]
]
wait []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment