Skip to content

Add request events #14

Description

@coreybutler

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions