Skip to main content

Entity Definition

note

This page is solely for educational purposes. It shows how to configure an api which per default connects to our BFF.

By default this is already configured in the default base and shop templates. Also this configuration most probably already exists in your project.

Define a new request

In order to get an executable request you need to create an action which returns an request.

1. Create a new file example.ts in the src/shop/client/actions directory. Now you can create a new example action as following:

import { createRequest } from 'shop/client/api';

import type { Example } from 'shop/client/interfaces/base';

export function actionGetExmaple(id: string) {
return createRequest<Example>({
url: `users/current/example/${id}`,
params: {
filter: 'done'
}
});
}

2. Add the export to shop/client/actions/index.ts

To have it easily available you need to add the export to the actions barrel export.

// Previous Exports
...

export * from 'shop/client/actions/payment';

3. Use the action

You can use the action now like a normal async function. It will return the result of the HttpFetch. It will throw if an error occurs (if configured), and it will use all the configured defaults etc. It will automatically handle Isomorphic behaviour and you can extend the behaviour through middlewares.

import { actionGetExample } from 'shop/client/actions';

await actionGetExample('EXMAPLE_ID');