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

Add request events #14

Open
coreybutler opened this issue Nov 13, 2022 · 0 comments
Open

Add request events #14

coreybutler opened this issue Nov 13, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@coreybutler
Copy link
Member

The client/resource modules are based on the EventEmitter, but they don't currently emit/relay events.

It would be nice to have the client/resource emit events about the request so the following scenarios would work:

API = new Resource({...})

API.on('request', event => {
  console.log(`Method: ${event.method}`)
  console.log(`URL: ${event.URL}`)
  console.log(`Body: ${event.body}`)
})

API.on('post', event => {...})
API.on('get', event => {...})
API.on('put', event => {...})
API.on('delete', event => {...})

The primary use case for this functionality is logging, but it could also be used for security hooks. Ideally, a before (i.e. before.post) and after (just post) version of each event would be useful, allowing developers to potentially abort or modify requests before they're actually sent.

This could also be useful for post-processing data, such as augmenting the response body of a request before inserting the data into an application.

@coreybutler coreybutler added the enhancement New feature or request label Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant