question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extending Context

See original GitHub issue

There is a request to extend Context. Discussed at #410 and https://github.com/honojs/honojs.dev/pull/1 The possibility of adding c.afunction() by the middleware is a good feature, I think.

But I don’t have any idea to implement it. One idea is using declare module:

declare module 'hono' {
   interface Context {
     afunction()
   }
 }

It seems to be not smart. Is there someone have other ideas?

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
RichiCoder1commented, Jul 27, 2022

And, also we want to implement adding “function” to Context, such as c.afunction().

I would like this ability, but mostly because I would like to add something like a ctx.auth() or ctx.trace().

That said, I’m fine creating a helper like getAuth(ctx) or getTrace(ctx) that uses get/set under the covers.

1reaction
yusukebecommented, Jul 30, 2022

Hi @usualoma !

I believe the following is often the good pattern for users

Agree. I think it would be easier for users to understand if there is an explicit method. So, the author of the middleware should provide a method like “validatoResult” if wants to get some values from Context.

Though we have this guideline, feature #429 is good for us. I’ll merge it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extend Context - Cortex XSOAR
You can extend context either in a playbook task, or directly from the command line. Whichever method you use, Cortex XSOAR recommends that...
Read more >
Extend Context - Palo Alto Networks
No information is available for this page.
Read more >
Extending context data returned by the Layout Service
Options for customizing the Sitecore context data. ... Extending context data returned by the Layout Service. Current version: 19.0.
Read more >
context extension in nLab
In dependent type theory, context extension introduces new free variables into the context. 2. Definition. If T is a type in a context...
Read more >
How to extend Context? #209 - oakserver/oak - GitHub
Now, I want to add some attributes to context,Whenever I want to return a JSON data, I need to write it ctx.response.body So...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found