Skip to content

Provide common utilities such as readJson #1346

Description

@cesco69

Some of the utility functions currently used in the examples are quite useful and generic enough that they could be provided by uWebSockets.js itself.

For example, a helper such as readJson could be exposed as part of the library instead of requiring users to copy the implementation from the examples.

This would have a couple of advantages:

  • users wouldn't have to copy and maintain these utilities themselves;
  • improvements and bug fixes could be propagated to all users through library updates;
  • examples could use the same utilities that are recommended for real applications;
  • it would make some common tasks easier without adding much complexity to the API.

For example, something along the lines of:

const { readJson } = uWS.utils;

app.post('/api', (res, req) => {
    readJson(res, () => {
        // ...
    });
    // ...
});

Have you ever considered providing some of these example utilities as part of the public API?

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions