The problem is here you want to return from fetch browser API, which returns Promise. If you really want to do it, for instance, instead of using useState hook in React to call and save the response in component state, then you need to wrap your fetch request into async IIFE function and use await statement to wait the async request to be fulfilled and the data to be resolved by Promise. For more info, you can refer: JS Fetch API access return value
json response from API replace with dummy data
Create a dummy REST API from a json file with zero coding in seconds
Anyone have a favorite free service that has dummy JSON that can be queried over HTTP?
Dummy JSON data element for rapid development
What are the different API key types?
How does the Image to API feature work?
What is a frontend-first backend?
Videos
The problem is here you want to return from fetch browser API, which returns Promise. If you really want to do it, for instance, instead of using useState hook in React to call and save the response in component state, then you need to wrap your fetch request into async IIFE function and use await statement to wait the async request to be fulfilled and the data to be resolved by Promise. For more info, you can refer: JS Fetch API access return value
write your fetch in an useEffect and set its response in a state
const [data, setData] = useState()
useEffect(() => {
fetch('API_URL', {method:"GET"})
.then(res => {
return JSON.parse(res);
}).then(response => {
setData(response)
})
}, [])
Hello guys, long time lurker on this sub but never posted before.
I created json-server, a CLI tool to create a dummy REST API from a provided json file with zero coding in seconds. For each provided resource 6 full functional endpoints are created (GET x2, POST, PUT, PATCH, DELETE), that you can use right away.
Inspired by the javascript package json-server that's where the name comes from.
The next step is to create the first release, which will include binary files for Windows, Linux and macOS. Any comments/suggestions are really welcomed. You can find more info at README file.
https://github.com/chanioxaris/json-server
When testing non-application-specific code (like middleware or generic architecture), I often would like to have something like placehold.it but for JSON. Something I can perform HTTP requests against when I don't necessarily care about what type of data I get back, as long as I get something. Do any of you know of a service like that?