Skip to content

Latest commit

 

History

History
54 lines (38 loc) · 1.02 KB

routing.md

File metadata and controls

54 lines (38 loc) · 1.02 KB

Basic Routing

Express routing definitions have the following pattern:

app.METHOD(PATH, HANDLER)

METHOD can be one of the get, post, put, delete, patch or all.

Examples:

Respond with Hello World! on the homepage:

app.get("/") { request in
    return Action.ok("Hello World!")
}

Respond to POST request on the root route /, the application’s home page:

app.post("/") { request in
    return Action.ok("Got a POST request")
}

Respond to a PUT request to the /user route:

app.put("/user") { request in
    return Action.ok("Got a PUT request at /user")
}

Respond to a DELETE request to the /user route:

app.delete("/user") { request in
    return Action.ok("Got a DELETE request at /user")
}

Respond to all methods requests on the /user route:

app.all("/user") { request in
    return Action.ok("Got a " + request.method + " request at /user")
}

Next tutorial: Static files