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

Combine persistent and one-time responses in one handler #1954

Open
1 task
kettanaito opened this issue Jan 6, 2024 · 0 comments
Open
1 task

Combine persistent and one-time responses in one handler #1954

kettanaito opened this issue Jan 6, 2024 · 0 comments
Labels

Comments

@kettanaito
Copy link
Member

Scope

Adds a new behavior

Compatibility

  • This is a breaking change

Feature description

How should the user describe a request handler where one logical branch returns a consistent response while the other a one-time response?

// From the V1:
rest.get('/resource', (req, res, ctx) => {
  if (a) {
    return res(ctx.text('One'))
  }

  return res.once(ctx.text('Foo'))
})

If the a condition won't be met, the res.once will be returned, terminating this handler. But if the condition is met, a consistent text response will be returned, preserving this handler.

V2 has no alternative to describe this behavior within a single handler since the { once: true } option applies to the entire request handler. You'd have to split this one into two, which is suboptimal.

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

No branches or pull requests

1 participant