Support Web APIs.

Open
#299 50 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
20/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
javascript
Domain
api, backend

Research direction

Start by reviewing the proposed MDN Response API and the existing njs request/response usage described in the issue, including the precontent phase and nginx subrequest behavior. Done would require a settled design and implementation for Request, Response, Headers, and Body without changing current usage, plus clearer subrequest examples and validation of the async model.

Written by the indexing model from the issue text.

Description

discussion njs

@xeioex @drsm

Web APIs is an alternative usage.
https://developer.mozilla.org/en-US/docs/Web/API/Response/Response
It will behave in njs like below.

function hello(request) {
      return new Response('hello');
}

function subrequest(request) {
      var sr = new Request('/sub');
      sr.fetch()
      .then(response) {
          return response;
      };
}

In the beginning, njs has individual response object. foo(req, res). After that, res is merged into req, so we have to rename some methods like headersIn, headersOut.
If we introduce these things, Request, Response, Headers, Body, I believe it can be easier to use, and we just implement the standard methods with them.
The second change is that the subrequest is also easier to use. Indeed, users need not know what subrequest is, they just want to send a request. (But the implementation will be upon on nginx subrequest).
Still, further, it can be welcome after async, await are introduced.

Highly welcome to your suggestions. I'd like to try it without changing current usage by put them in precontent phase.

I'm still not familiar with async, await, Promise, it's good to have a better example of how to write with subrequest below. @drsm

BTW, do you know whether the above objects are standard belong to js?
I'm wondering which software has already implemented them, where are they used?

Dominant language
C
Stars
1.6k
Forks
245
Avg merge
2d 5h
Merged PRs (30d)
6

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nginx/njs

All issues in nginx/njs

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.