documentation
documentation copied to clipboard
[Request]: Add documentation of `ctx`
Summary
The context object is mentioned multiple times in the Strapi docs, yet the docs lack an explanation of its structure and included methods, e.g., requests-responses.
Various folks mentioned on Discord that ctx
is a Koa construct, yet various methods like ctx.send(...)
, which are mentioned in the Strapi docs, are not mentioned in the Koa docs.
It would be helpful to have some documentation available or a reference to external resources where the various ctx
methods like send
are listed and explained in detail.
Why is it needed?
It's part of Strapi but it's not documented.
Suggested solution(s)
No response
Related issue(s)/PR(s)
No response
Hi @rikonor, thank you for creating this issue. I'm sorry you're having trouble with the Strapi methods built around Koa. I've asked for clarification from our back-end developers and will keep you posted 🙂
Indeed, send()
is a custom method added by the Strapi core code on top of Koa's existing API.
These custom methods are defined here in Strapi source code. Strapi also added the created()
and deleted()
methods.
We will improve our existing documentation with this information. Thank you so much for highlighting this!
There is a lot of stuff in the ctx we need to document, I think it might be worth it in this case to also document some native koa stuff too. We used to have a link and some very light docs ages ago (like v3-alpha days) but the koa documentation is largely pretty bad.
@pwizla Would you mind if I wrote like a list of everything in the ctx that I know of? Also if I where to do this where would you want this list and how would you want it formatted.
My plan basically was to use a graph at the top of the section with where needed links to table row bellow it.
then have a table for all the routes and the information you need to have for it
so we would have both visual + text and is it not just a table with 40 rows where you need to search in
Will start with the table first and then once you guys have decided what to do graph wise I then I will add the graph
but for this to work the graph would have to have links else it is useless
That sounds like a good plan, @Boegie19!
I would probably add that to the requests/responses docs.
I want to maintain your creativity and plans for the graph: independently of what I said in #1666; if you feel like you need Mermaid to build your vision, go for it. 🚀🙂 Right now, my Koa knowledge is limited. It will be easier for me to decide on a proper structure and reformat/rewrite stuff if necessary once I have a better overview of the whole content. That's how I work: gather source material, lay out the content only after, then draft, then rewrite, etc. — the same applies to the graph; better to decide on the proper tool or design once the draft is in place. I don't necessarily want Mermaid applied all over the place in the Strapi docs, but if it's useful for some use cases, why not 🤷 (until we possibly find a better solution). We can also have a call mid-term of your project if you don't want to invest too much time :)
Closing this one as it was finally handled and published 🥳 🚀 👉 https://docs.strapi.io/dev-docs/backend-customization/requests-responses