Skip to main content

Context

What is Context in Graphul?​

Context is a struct accessible in any handler and it provides the utils most used, with which we can access the params, queries and payload among other important properties.

app.get("/", |c: Context| async move {
// ... your code
});
note

If we declare a State into the routes we can use it from here.

Context methods​

Here is a table with the name, the return types and the description of every method

MethodReturn typeDescription
addrSocketAddrAn internet socket address
all_params&HashMap<String, String>Return all the path params with its values
all_query&HashMap<String, String>Return all the query params with its values
bodyStringReturn the body of the request into a String
bytes&BytesReturn the body of the request in Bytes
headers&HeaderMapReturns a reference to the associated header field map.
ipIpAddrReturn the Ip of the server
jsonJson<Value>Return the body as a Json
method&MethodReturn the method of the request
paramsStringReturn all the values of the path param
parse_paramsResult<Json<T>, JsonRejection>Return all path params into a Struct wrapped into a Json
parse_queryResult<Json<T>, JsonRejection>Return all queries params into a Struct wrapped into a Json
payloadResult<Json<T>, JsonRejection>Return the body as a Struct wrapped into a Json
queryStringReturn the value of a query param
stateInnerState<T>Return the state of the app, if you are not sharing a state the default value is a empty tuple «()»
uri&UriReturns a reference to the associated URI.
versionVersionReturns the associated HTTP version.