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: {
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
path: string;
body?: string;
query?: string;
headers: string;
}) => string
endpoint: resolvers.interface resolvers.Root
Root["endpoint"] = (req: {
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
path: string;
body?: string;
query?: string;
headers: string;
}
req) => {
switch (`${req: {
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
path: string;
body?: string;
query?: string;
headers: string;
}
req.method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS"
method} ${req: {
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
path: string;
body?: string;
query?: string;
headers: string;
}
req.path: string
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 Endpoint URL” 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
.