Divooka Reference

Web Apps

17 nodes

On this page 17

Create Web App

Function

A new web app with no endpoints yet.

Signature
CreateWebApp(name: Text) -> Web App
WebApp CreateWebApp(string name = "Web App")

Parameters

nametypedefaultdescription
nameTextWeb AppWhat the app is called, in its OpenAPI document.

Returns

AppWeb App
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Map Delete

Function

Answers DELETE requests on a route with a function.

Signature
MapDelete -> Web App
    app: Web App
    pattern: Text
    handler: Delegate
WebApp MapDelete(WebApp app, string pattern, Delegate handler)

Parameters

nametypedefaultdescription
appWeb App—
patternText—
handlerDelegate—

Returns

AppWeb App
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Map Fallback

Function

Answers every request no endpoint or file answered - a 404 page, or a single-page app's index.

Signature
MapFallback(app: Web App, handler: Delegate) -> Web App
WebApp MapFallback(WebApp app, Delegate handler)

Parameters

nametypedefaultdescription
appWeb App—
handlerDelegate—

Returns

AppWeb App
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Map Get

Function

Answers GET requests on a route with a function: /todos/{id} fills an input named Id.

Signature
MapGet -> Web App
    app: Web App
    pattern: Text
    handler: Delegate
WebApp MapGet(WebApp app, string pattern, Delegate handler)

Parameters

nametypedefaultdescription
appWeb App—
patternText—The route, with any values in braces; ASP.NET Core's constraints work too ({id:int}).
handlerDelegate—The function that answers - graph:Name for one of this document's graphs. Its inputs are filled from the request by name; what it returns is the answer.

Returns

AppWeb App
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Map Group

Function

Puts another app's endpoints under a prefix - /api - as ASP.NET Core's route groups do: build the group's endpoints in an app of their own (and require a key on them there, if they need one), then map the group.

Signature
MapGroup(app: Web App, prefix: Text, group: Web App) -> Web App
WebApp MapGroup(WebApp app, string prefix, WebApp group)

Parameters

nametypedefaultdescription
appWeb App—
prefixText—What every route of the group starts with.
groupWeb App—The app holding the group's endpoints.

Returns

AppWeb App
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Map Methods

Function

Answers requests of several methods - HEAD, OPTIONS or any other - on a route with one function.

Signature
MapMethods -> Web App
    app: Web App
    methods: Text Array
    pattern: Text
    handler: Delegate
WebApp MapMethods(
    WebApp app,
    string[] methods,
    string pattern,
    Delegate handler)

Parameters

nametypedefaultdescription
appWeb App—
methodsText Array—The methods, such as GET and HEAD.
patternText—
handlerDelegate—

Returns

AppWeb App
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Map Patch

Function

Answers PATCH requests on a route with a function.

Signature
MapPatch -> Web App
    app: Web App
    pattern: Text
    handler: Delegate
WebApp MapPatch(WebApp app, string pattern, Delegate handler)

Parameters

nametypedefaultdescription
appWeb App—
patternText—
handlerDelegate—

Returns

AppWeb App
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Map Post

Function

Answers POST requests on a route with a function; a record or class input is read from the JSON body, simple inputs from its fields or a form.

Signature
MapPost -> Web App
    app: Web App
    pattern: Text
    handler: Delegate
WebApp MapPost(WebApp app, string pattern, Delegate handler)

Parameters

nametypedefaultdescription
appWeb App—
patternText—
handlerDelegate—

Returns

AppWeb App
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Map Put

Function

Answers PUT requests on a route with a function.

Signature
MapPut -> Web App
    app: Web App
    pattern: Text
    handler: Delegate
WebApp MapPut(WebApp app, string pattern, Delegate handler)

Parameters

nametypedefaultdescription
appWeb App—
patternText—
handlerDelegate—

Returns

AppWeb App
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Require Api Key

Function

Requires a key on every endpoint mapped so far: a request without the header, or with another key, is answered 401. Map the endpoints first; on a group, require it in the group's own app before mapping the group.

Signature
RequireApiKey(app: Web App, key: Text, header: Text) -> Web App
WebApp RequireApiKey(
    WebApp app,
    string key,
    string header = "X-Api-Key")

Parameters

nametypedefaultdescription
appWeb App—
keyText—The key the header must carry.
headerTextX-Api-KeyThe header it comes in.

Returns

AppWeb App
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Run

Function

Runs the app until the program ends, or the run it belongs to is stopped - the last step of a program whose job is to serve.

Signature
Run(app: Web App, URL: Text)
void Run(WebApp app, string url = "http://localhost:5000")

Parameters

nametypedefaultdescription
appWeb App—
URLTexthttp://localhost:5000Where it answers: http://localhost:5000 for this machine, http://0.0.0.0:5000 for the network. A host that runs the document - the Divooka platform, an assistant testing it - answers where it says instead.

Remarks

Round 26: a run's Stop shuts the app down and Run returns, through Contracts.DivookaRunCancellation, which the editor sets around a run; Run used to wait for the process to be told to end, which inside the editor never came.

Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Start

Function

Starts the app in the background and returns at once with where it answers - for a program that serves as one step, calls itself, and stops; it stops on its own after Max Seconds.

Signature
Start -> Running Web App
    app: Web App
    URL: Text
    maxSeconds: Number
RunningWebApp Start(
    WebApp app,
    string url = "http://127.0.0.1:0",
    double maxSeconds = 60)

Parameters

nametypedefaultdescription
appWeb App—
URLTexthttp://127.0.0.1:0Where it answers; port 0 takes a free one, which the result's Address says.
maxSecondsNumber60The longest it runs before stopping on its own.

Returns

RunningRunning Web App
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Stop

Function

Stops an app Start started and releases its port; stopping one that has stopped does nothing.

Signature
Stop(running: Running Web App)
void Stop(RunningWebApp running)

Parameters

nametypedefaultdescription
runningRunning Web App—
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Use Cors

Function

Lets pages from other sites call the app from a browser (CORS): the origins allowed, or * for any.

Signature
UseCors(app: Web App, origins: Text Array) -> Web App
WebApp UseCors(WebApp app, string[] origins)

Parameters

nametypedefaultdescription
appWeb App—
originsText Array—Origins such as https://example.com, or *.

Returns

AppWeb App
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Use Open Api

Function

Describes the app's endpoints as an OpenAPI 3 document at a path - what Swagger UI, Postman and code generators read - from its routes and its handlers' inputs.

Signature
UseOpenApi -> Web App
    app: Web App
    title: Text
    version: Text
    path: Text
WebApp UseOpenApi(
    WebApp app,
    string title = "",
    string version = "1.0",
    string path = "/openapi.json")

Parameters

nametypedefaultdescription
appWeb App—
titleText—
versionText1.0
pathText/openapi.json

Returns

AppWeb App
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Use Request Logging

Function

Prints a line for every request - method, path, status and time - to the program's output.

Signature
UseRequestLogging(app: Web App) -> Web App
WebApp UseRequestLogging(WebApp app)

Parameters

nametypedefaultdescription
appWeb App—

Returns

AppWeb App
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications

Use Static Files

Function

Serves the files of a folder - pages, scripts, pictures - with index.html for a folder's own address.

Signature
UseStaticFiles -> Web App
    app: Web App
    folder: Text
    requestPath: Text
    defaultFiles: Truth
WebApp UseStaticFiles(
    WebApp app,
    string folder = "wwwroot",
    string requestPath = "",
    bool defaultFiles = true)

Parameters

nametypedefaultdescription
appWeb App—
folderTextwwwrootThe folder, relative to the document (wwwroot, site).
requestPathText—Where under the app it is served; empty for the root.
defaultFilesTruthTrueWhether a folder's address serves its index.html.

Returns

AppWeb App
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Web Apps
Package
Web Applications