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!
#Mocking backend calls
1 messages · Page 1 of 1 (latest)
🔎 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)
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
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.
@rugged latch solved?
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
hmm ok. When you just want to return different data, then build your own api endpoints, that return static data. Depending on the requested data, the variables, the headers, the cookies, ... you can return different data and remove/add specific keys to the response. Like that you can mock your backend calls and work with the data
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
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)
Please mark solution:
✅ Success!
This question has been marked as answered! If you have any other questions, feel free to create another post
Jump to answer
[Click here](#1344469427420397660 message)