loopbackio / loopbackio/loopback-next
Docs: How to receive context in controller
Open
Nobody has claimed this yet.
developer-experience
Docs
good first issue
help wanted
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 27
Description
Is there any way to receive the context inside a controller?
Goal is to access request data (headers, ip, etc.)
Thanks
Acceptance criteria
- a section in Controllers.html explaining how to access request and response headers or body by using decorators like
@inject(RestBindings.Http.REQUEST) public request: Requestfor different cases:- A request header shared by most (or all) endpoints and processed by an express middleware/LB4 sequence action. Example: Authorization or X-API-Key.
- A request header shared by many endpoints but used internally in the endpoint implementation (an express route handler/LB4 controller method). Maybe come up with a somewhat realistic example of such header.
- A response header set by an express middleware/LB4 sequence action. For example X-Rate-Limit information provided by a rate-limiting extension in all responses.
- A response header set by the endpoint (an express route handler/LB4 controller method). An example: Location header included ind 201 Created responses.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Controllers.html and the documented @inject(RestBindings.Http.REQUEST) pattern. Add examples covering request and response headers or bodies in middleware or sequence actions and controller methods, including the Authorization or X-API-Key, rate-limit, and Location cases, then verify every acceptance criterion is addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, typescript
- Domain
- api, documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100