Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support async response function #152

Open
rochejul opened this issue Dec 15, 2022 · 1 comment
Open

Support async response function #152

rochejul opened this issue Dec 15, 2022 · 1 comment
Labels
feature request New feature or request

Comments

@rochejul
Copy link

Hi

We could define a function when we want to return a custom response.

It should be great if it supports async response. Especially if we want to call a mock server.

It could be evolved like so:

setTimeout(async () => {
    let payload = response;

    if (typeof response === 'function') {
        payload = response(request);

        if (response.constructor.name === 'AsyncFunction' || payload instanceof Promise) {
            payload = await payload;
        }
    }

    resolve(new Response(url, status, payload));
}, +delay);

Thoughts?

@nutboltu nutboltu added the feature request New feature or request label Jul 5, 2023
@rChaoz
Copy link

rChaoz commented Apr 16, 2024

I think this is a necessary addition. My use case is very simple - I want to read the JSON send by the client and create a response based on that. This is sadly not possible, as Request.json() returns a promise. Any workarounds for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants