Endpoints in Stamhoofd are stored in backend/app/<app name>/src/endpoints


Inputs

An endpoint has three input options:

And responds with an encodeble object, a string, a stream or no data at all (undefined).


Usage

Requests with query params

<aside> 💡

The endpoints do contain some boilerplate code in the doesMatch method, in the future we’ll probably want to simplify that.

</aside>

// Params: we don't have them: so set it's type to an empty object
type Params = Record<string, never>;

// Define the type of your query parameters (you can use an Encodeable object)
type Query = LimitedFilteredRequest;

// Define the type of your body
type Body = undefined;

// Define the type of your response
type ResponseBody = Member;

export class GetMembersEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
    // When specifying a query, you'll need to set the queryDecoder here:
    queryDecoder = LimitedFilteredRequest as Decoder<LimitedFilteredRequest>;

    protected doesMatch(request: Request): [true, Params] | [false] {
        if (request.method !== 'GET') {
            return [false];
        }

        const params = Endpoint.parseParameters(request.url, '/members', {});

        if (params) {
            return [true, params as Params];
        }
        return [false];
    }

    async handle(request: DecodedRequest<Params, Query, Body>) {
		    const member = Member.create({...});
        return new Response(
            member,
        );
    }
}

Requests with body