-
Notifications
You must be signed in to change notification settings - Fork 202
docs: add api-requests guide #823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds a centralized guide on where and how to organize API request logic and removes inline examples from other docs in favor of linking to the new guide.
- Moved detailed “where to store request” examples out of the auth guide into a standalone API-requests guide
- Removed an outdated auto-generation types section in the types guide
- Introduced
api-requests.md
with shared and slice-specific patterns, client setup, and generator recommendations
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
i18n/en/docusaurus-plugin-content-docs/current/guides/examples/types.md | Removed “Auto-generation of types” section |
i18n/en/docusaurus-plugin-content-docs/current/guides/examples/auth.md | Replaced inline API‐request examples with a reference link |
i18n/en/docusaurus-plugin-content-docs/current/guides/examples/api-requests.md | Added new guide covering shared/slice-specific request patterns |
Comments suppressed due to low confidence (2)
i18n/en/docusaurus-plugin-content-docs/current/guides/examples/types.md:431
- [nitpick] The removal of the auto-generation section removes guidance on handling generated types; consider linking to an external guide or summarizing key steps for regenerating types in a dedicated folder.
## Auto-generation of types
i18n/en/docusaurus-plugin-content-docs/current/guides/examples/api-requests.md:14
- [nitpick] Indent this list under 'A typical file structure would be:' by two spaces (e.g.
- 📂 shared
) to ensure proper nesting and consistent markdown rendering.
- 📂 shared
i18n/en/docusaurus-plugin-content-docs/current/guides/examples/auth.md
Outdated
Show resolved
Hide resolved
i18n/en/docusaurus-plugin-content-docs/current/guides/examples/api-requests.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like how the new page reads, great work! I have some concerns about how the other pages link to this one though — I'd like to see the link more naturally integrated into the narrative
|
||
# Handling API Requests | ||
|
||
Feature-Sliced Design provides a structured way to organize your API request logic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: I don't think this statement is very accurate — FSD doesn't provide a way to organize API request logic. I'd say the more accurate description is "here's how to organize request logic with the whole FSD structure"
suggestion: maybe we don't even need this intro and can get straight to the first section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, abstract intro looks fine in theory, but doesn't add any meaningful information
- Default headers (e.g., for authentication). | ||
- Data serialization. | ||
|
||
Here are examples for `axios` and `fetch`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (non-blocking): perhaps it would be clearer if we split the axios and fetch examples into different codeblocks? To demonstrate that they are not meant to be used together
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
export interface LoginCredentials { | ||
email: string; | ||
password: string; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: I believe it's very common nowadays to pair your backend DTO definitions with runtime data validation with Zod or the likes, perhaps we can add something about it here? Maybe a link to the relevant section of the Types guide will suffice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: great job with this file! It's concise and to the point :)
@@ -429,10 +429,6 @@ Other packages simply don't have typings, and you might want to declare them as | |||
declare module "use-react-screenshot"; | |||
``` | |||
|
|||
## Auto-generation of types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: I don't quite like the idea of removing this section entirely. If I was searching for autogeneration of types, I might look in Types or I might look in API requests.
suggestion: I'd prefer if both pages could pick the user up where they are and show them the way. Perhaps we could also do it in a more elaborate way than just having a link — perhaps we can offer some useful clarifications about the content of that link, i. e. how the content of the link applies to the problem at hand.
So basically I would suggest keeping the heading as is, giving a link to the guide, and also saying something like "if you want to auto-generate types from an OpenAPI schema, put them in shared/api/openapi
. If you want to auto-generate types from a Figma icon library, put them in shared/ui
.
In fact, maybe we can just paraphrase and not even bother linking, it's just one small paragraph
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rolled this change back to focus on one page at a time, later we can revisit this paragraph if needed
|
||
## Using Client Generators | ||
|
||
If your backend has an OpenAPI specification, tools like [orval](https://orval.dev/) or [openapi-typescript](https://openapi-ts.dev/) can generate API types and request functions for you. Place the generated code in `shared/api`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: I suspect some people will also want guidance on where in shared/api
to put the generated code. What was nice about the previous version on another page is that it specified a concrete example — shared/api/openapi
suggestion: let's give a specific location here as well, and if they don't like it, they can come up with their own
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: I also like this sentence from the previous version:
Ideally, you should also include a README in that folder that describes what these files are, how to regenerate them, etc.
Could we add that here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
``` | ||
|
||
You don't have to export the `login()` function in the page's public API, because it's unlikely that any other place in the app will need this request. | ||
Create a function that makes a request to your backend's login endpoint. This function can either be called directly in the component code using a mutation library (e.g. TanStack Query), or it can be called as a side effect in a state manager: [where to store the request function][examples-api-requests]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: this link kinda feels patched on top of the text, it doesn't flow naturally, in my opinion.
suggestion: like I wrote in another comment, maybe we could give some clarification about the content of that link, how it's relevant here? Because the linked page is talking about API requests in general, and here we have a very particular API request, so we can offer more precise advice.
I see it as something like "As explained in the [guide for API requests], you can put your request either in shared/api
or in the api
segment of your login page."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Background
Some guides on where to place API requests. I added only the English version first to gather feedback.