#Mocking backend calls

1 messages · Page 1 of 1 (latest)

rugged latch
#

Im only using NextJS for frontend and a different backend. i want to mock the api calls to get or update or delete stuff in a (for now mock) database, what tools should i use?
jwt authentication will be used. i want the code to be able to simulate a backend and make it easy to transition to the real one once its ready. thanks!

meager chasmBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

crimson canopy
# rugged latch Im only using NextJS for frontend and a different backend. i want to mock the a...

you can create an actual database and do everything like you would do on a real DB. Call this "test DB" then something like "test_db" or similar and then work with it. After you tested everything and worked with it, you only need to change the credentials to your "real DB", call it "real_db" or something simlar and everything should work like expected automatically. Manage it easily with .env.local and .env.production.local

balmy talon
#

To top off the info: you can create .env variables locally and when you are hosting.
So when you are developing you point to the local DB. And when it’s deployed it automatically points to the hosted prod DB.

crimson canopy
#

@rugged latch solved?

rugged latch
#

hey, no,
so far ive worked with variable arrays that act as db tables, that i modify through a function with react query.
i dont know what tools exactly i should use and in what way to do the whole thing for it to also be good for unit testing etc

#

thanks

#

of course i can use an actual database but in this case i feel this would defeat the purpose

crimson canopy
rugged latch
#

so far I've read things about msw and jest

#

but anyway, so far i can work with the variables and simply replace the function calls in react query with actual api calls

#

thanks

#

consider it solved

crimson canopy
# rugged latch so far I've read things about msw and jest

yea, jest is more for testing and not for an actual runtime env. Using msw can also be a possible way. If I would be to, I would create a simple test DB like I mentioned to easily migrate to the real DB (as you using a DB in the future as well)

crimson canopy
meager chasmBOT
crimson canopy