- Advanced Node.js Development
- Andrew Mead
- 411字
- 2021-08-27 19:06:03
Illustrating working of the JSON data
So to illustrate how JSON data works, we're going to make a request to the geocoding URL that we used earlier in the course. If you remember, we were able to pass in a location and we got some JSON back, describing things like the latitude and longitude, and the formatted address. Now this should still be in your Chrome history.
If you deleted your history, you can go ahead and put https://maps.googleapis.com/maps/api/geocode/json?address=1301+lombard+st+philadelphia in the address bar. This is the URL I'll be using; you can simply copy it, or you can grab any JSON API URL. I'm going to copy it to the clipboard, head back into Postman, and swap out the URL with the URL I just copied:
Now, I can go ahead and fire off the request. We get our JSON data, which is fantastic:
We're able to see exactly what comes back when we make this request, and this is how we're going to be using Postman.
We'll use Postman to make requests, add Todos, delete Todos, get all of our Todos, and log in; all of that stuff is going to happen right in here. Remember, APIs don't necessarily have a frontend. Maybe it's an Android app; maybe it's an iPhone app or a web app; maybe it's another server. Postman gives us a way to interact with our API, making sure it works as expected. We have all of the JSON data that comes back. In the Raw view, which is under Body, we have the raw data response. Essentially, it's just unprettified; there is no formatting, there is no colorization. We also have a Preview tab. The Preview tab is pretty useless for JSON. When it comes to JSON data., I always stick with the Pretty tab, which should be the default.
Now that we have Postman installed and we know a little bit about how to use it, we're going to move on to the next section, where we will actually create our first request. We'll be firing off a Postman request to hit the URL we're going to create. This is going to let us make new Todos right from Postman or any other application, whether it's a web app, a mobile app, or another server. That's all coming up next, so just make sure you have Postman installed. If you were able to do everything in this section, you are ready to continue.