Call an API within getServerSideProps or just access the database #15750
-
I'm in a bit of a quandry at the moment and i wonder if someone can help me figure this out. I have a simple application. You login, then it should take you to a 'userdetails/create' page allowing the user to populate some more data. My current plan is to utilise getServerSideProps to:
At the moment i'm using an API to get the existing user details. But all this does is:
I guess my question is. What is the point of doing the API call if all it's doing is accessing a database on the serverside. Why dont i just access the database directory to solve my problem? This would save me
The page, api and also the DB connection / user details service layer are all within the same codebase. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Sounds like you have your answer 😄 if all of your application logic is self contained already in your project, I'd say just include your logic in I don't think you can go wrong, but it sounds like you have more pros than cons for putting it in Just my 2 cents 🚀 |
Beta Was this translation helpful? Give feedback.
Sounds like you have your answer 😄 if all of your application logic is self contained already in your project, I'd say just include your logic in
getServerSideProps
if it is only relevant for that page it is used in and will only be consumed internally within your application.I don't think you can go wrong, but it sounds like you have more pros than cons for putting it in
getServerSideProps
.Just my 2 cents 🚀