-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add network request example with layered architecture #279
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
Conversation
- Added externalHandlers.js to simulate external API responses for posts and comments. - Updated routes to include new external API mock routes. - Refactored postHandlers to call the new external API endpoints. - Adjusted server.js to export base URL for easier configuration. - Enhanced test setup to mock external API calls correctly. Resolves: no-ticket Signed-off-by: [Balint Lendvai] <[email protected]>
- Moved server configuration constants (port and base) from server.js to a new config/server-config.js file for better organization and testability. - Updated imports in postHandlers.js and test files to reflect the new configuration module. - Adjusted response handling in tests to use HttpResponse from msw. Resolves: no-ticket
…outing and parameter handling - Added a utility function to determine active menu items based on current path, supporting dynamic routes. - Updated NavHeaderItems to utilize the new active path logic. - Enhanced Dashboard component to access and display URL path and query parameters. - Configured routing to support dynamic dashboard paths with parameters. Resolves: no-ticket
rodet
left a comment
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.
Looks good overall! Please review my comments. Later on we should add more test cases but this could be a separate PR.
lee-chase
left a comment
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.
@bogy0 made a small number of changes to fix preview:prod.
Turns out that at run time Express insists on the whole object being selected.
I was also a bit confused about the posts/comments.
The id and postId always seemed to be one.
In addition it would be nice to prevent invalid IDs. Suggest 400 for invalid ID, 404 for out of range/not found.
|
@lee-chase Thanks for your changes to make the For your other comments:
The Welcome page's
Again this is just an example usage, if you have better idea how you want to demonstrate this in the Welcome page, let me know, but based on your comment im more like confused, then confident whats the goal. If you want to i can write a random
The carbon-react-router-starter/src/service/externalHandlers.js Lines 94 to 96 in e037b45
|
|
Hi @bogy0, perhaps my understanding of what we are demonstrating is incorrect. I expected postId and id to match some back end identifier and thought by changing the params I might see that. As for the 404: "Post not found" that is correct, but if the wrong ID format is supplied it may be more appropriate to return 400: Bad request. Happy for you to reject both these thoughts and approve. |
also added JSDoc for PostComponent Resolves: no-ticket
@lee-chase now i understand, sorry for my confusion, so what i did to address this in my latest commit (9a3fb40) is that i added a |
Issue being raised to deal with test coverage.


This PR adds a simple end-to-end example of how to fetch data. The goal is to give developers a real example how to do this.
(FYI: This PR is a rework of #87. The original branch was created about three months ago and diverged significantly from main, so I recreated the feature on a fresh branch based on the latest main.)
This PR also gives example how to access params/queries in client component
What’s included
PostComponent example
Added a small React component that loads a "blog post" + its "comments". It shows:
Clear separation between layers
src/pages/welcome/post/PostComponent.jsxsrc/api/message.jssrc/service/postHandlers.js, src/service/externalHandlers.jsThis should make the overall flow easier to follow and copy/paste for future features, also testing can be easier.
New endpoints
These external endpoints are mocked
— they’re only here to demonstrate how the service layer would normally proxy to some real third-party service.
Dashboard extended with handling url params/queries
/dashboard/1234?q=xxx&name=AnneThis is how this new section looks in the welcome page:
Modified dashboard page, to demonstrate how to handle params/queries client-side: