HTTP Endpoints
Every Membrane program has its own URL and can handle requests made to that URL. This provides a simple mechanism for calling into your membrane programs from the outside world.
export const const endpoint: (req: any) => string
endpoint = (req: any
req) => {
switch (`${req: any
req.method} ${req: any
req.path}`) {
case "GET /":
return "hello world";
default:
return var JSON: JSON
An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
JSON.JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)
Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
stringify({ status: number
status: 404 });
}
};
When your program endpoint receives a request it will be logged, so you can inspect it in the Logs panel.
Accessing an endpoint URL
To access a program’s endpoint URL in your code, call:
await nodes.process.endpointUrl
To open an endpoint, click “Open Preview” above the endpoint
function signature. You can also copy a program’s endpoint by right clicking on it in the Navigator panel.
http program
There is also an http
program pre-installed in your workspace. When you run fetch
in a program, Membrane uses its HTTP program behind the scenes to make network calls. Read on to learn how to add connections to programs, including http
.