Function URLs
Each function in EXM is assigned a URL that can be used to request or read the function without necessarily having an EXM account. The syntax of this URL is the following:
https://{EXM_Function_Id}.exm.run
- No need for users to have an EXM account
- URL is easily exposable with no private tokens in it
- Improves both developer and user experiences bridging web2 and web3 concepts even more
- Easily reading the state of a function
The usage of these URLs is quite simple. You will need to do a POST request where the JSON Body will be considered the input (
action.input
).For example, let's take a look at the following code (Deployed under
Ej2_F6KyxJ3216hupMcfC0keC8BSmjPNLgoviGoxeFk
):/**
*
* @param state is the current state your application holds
* @param action is an object containing { input, caller } . Most of the times you will only use `action.input` which contains the input passed as a write operation
* @returns {Promise<{ users: Array<{ username: string}> }>}
*/
export async function handle(state, action) {
const { username } = action.input;
state.users.push({ username });
return { state };
}
In order to request this code, we would do the following cURL call:
curl --location --request POST 'https://Ej2_F6KyxJ3216hupMcfC0keC8BSmjPNLgoviGoxeFk.exm.run' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "Andres Pirela"
}'
This would make the state equal to
{"users":[{"username":"Andres Pirela"}]}
Query Parameter | Value | Description | Optional |
---|---|---|---|
ignoreState | Boolean | Whether state should not be returned | Yes |
With the URL of a function, you can additionally read its state by making a
GET
request to the URL. In this case, opening this URL (https://ej2_f6kyxj3216hupmcfc0kec8bsmjpnlgovigoxefk.exm.run/) in your browser would essentially give you the state that ej2_f6kyxj3216hupmcfc0kec8bsmjpnlgovigoxefk
holds.