Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.
HARADA Koichi edited this page Apr 21, 2020 · 8 revisions

About HTTPServer component

HTTPServer is a 4D component, built with 4D v18, which includes methods to help your web developing.

Installation

This is a 4D component, so you should build this source as 4D component and place it in the "Components" folder of your project root.

Hello World

httpServer.conf

Copy httpServer.conf file and place it on your project root. You can find the file in this sample's project root.

On Web Connection database method

Write following code in On Web Connection database method. OnWebConnection is a shared component method.

C_TEXT($1;$2;$3;$4;$5;$6)
OnWebConnection($3;$4)

On Startup database method

Then write following code in On (Server) Startup database method. new HttpServer is also a shared component method which is used to build your web application.

C_OBJECT($app_o)
$app_o:=new HttpServer()
$app_o.get("/hello"; Formula(HelloWorld))
$app_o.start()

HelloWorld method looks like

C_OBJECT($1;$req_o)
C_OBJECT($2;$res_o)
C_OBJECT($3;$next_o)
$req_o:=$1
$res_o:=$2
$next_o:=$3
$res_o.send("Hello World")

Then restart your project, make sure the HTTP server is up and running, connect to http://localhost/hello with your favorite web browser. You will get "Hello World" response.

More How Do I's

Please refer to the demo is in the "test" folder. Just launch it with 4D v18 Standalone and connect to it with your favorite web browser via http://localhost/.