Examples
Loading the library
using MongooseGET endpoint with query params
function greet(conn, request)
query = mg_query(request)
matches = match(r"name=([^&]*)", query)
if !isnothing(matches)
return mg_text_reply(conn, 200, "Hi $(matches.captures[1])")
else
return mg_text_reply(conn, 200, "Hi unknown person")
end
end
mg_register!("GET", "/greet", greet)POST endpoint with body
using JSON
function saygoodbye(conn, request)
body = mg_body(request)
dict = JSON.parse(body)
json = Dict("message" => dict["name"]) |> JSON.json
return mg_json_reply(conn, 200, json)
end
mg_register!("POST", "/saygoodbye", saygoodbye)Start server
mg_serve!()End server
mg_shutdown!()