Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialkyle pfromer
12,597 PointsConsuming A Rest API
I know this course is about making the rest API but this question is about how to consume it. My question is how do you consume the rest API (with express preferably)? For example, could I make one express server that is the rest API and have another express server that calls the rest API and renders and manages the web front end aspect (sessions and so on)?
The reason I ask this is because I have followed the course on creating a user authentication system with express and would like to use that code to connect to a rest API.
If there is a better way of consuming a rest API for the web aspect please tell me! Thanks,
 Kyle Pfromer
Jordan Watson
14,738 PointsJordan Watson
14,738 PointsI see where you are coming from essentially you can do either or so here are some options:-
You can create an API that handles only the data from the users and tie a user ID to the question or answers. This course illustrates how to store the data from the user in to database and render based on the query string provided.
Although you could merge the two of course principles in to one project and by using MongoDB to have different documents listed in the DB such as Answers, Questions, Users and Sessions that way its just as easy to make relationships between user questions and answers.
Although it is possible to have two node servers running separately and have them communicate together, fetching questions etc from one API and user details from another its entirely up to yourself it really depends how modular you want things to be?