![]() Postman assumes any URL that doesn't begin with a scheme ( or actually starts with and adds that to the URL when making a request. You might have noticed the URL we just used started with Just like a web browser can load pages securely using HTTPS, APIs can be accessed using these secure URLs as well. We'll be working with JSON throughout this book, but it isn't important to understand everything about how it works right now. This format is commonly used when formatting data for consumption by other computers as it has a very well defined structure and is widely supported by both servers and clients. The response is in JSON format, which is a way to represent data that was derived from the JavaScript language. ![]() Unlike the previous responses, there is no HTML, CSS, or JavaScript in the response there is nothing to describe how to display the data other than its structure. This request returned a response that is designed for consumption by a computer, and only the data itself is represented. We'll use the same search term, the URL, and an additional query parameter format (which should have the value json). This API returns a list of links similar in structure to the kind of results a search engine would return. DuckDuckGo provides an API to access its instant answers functionality. Let's see what happens when we make a request to a web API that is designed to return simple, cleanly formatted responses. API responses are typically just data, represented in a way that makes it easy to put to use. Web APIs can do a lot of the same things that a user can do through a web browser, but since they are intended to be used by computer programs, there is no need to specify how the data should be presented. Assuming we just wanted the list of search results for some other use and didn't want to deal with all of the other content, wouldn't it be nice to just get the data? The page includes instructions on what color and size the links should be, some JavaScript code that adds mouse-over effects, and so on. The response is so large not because of the size of the data itself, but all of the other information about how to display it that is included. If you consider how this page really just displays ten or so links and summaries, it seems inefficient to bury that information in such a mountain of markup, styles, and scripts. Due to the complexity and structure of the code (and how it is optimized for size), it would be difficult to do anything other than display this code in a web browser. Scroll around and take a look at how much code there is just to display this web page. You might look at this mess of HTML, CSS, and JavaScript and wonder how anything useful could be done with it. Click Send again to send this new request.Īssuming the response code is 200 OK, the response is the markup used to display a typical Google search result page. ![]() ![]() Let's put this knowledge to use by appending this path to to build the URL and adding a parameter with a search term. Instead of spending time on that, though, it's better to just tell you that the path for searches is /search and the query parameter that needs to be sent is q. If we were to dig into this HTML, eventually we would find the form and input elements, from which we could figure out how to build the query to perform a search. Luckily, we have computers and web browsers to do that for us. The HTML code of this page is heavily optimized to be as small as possible, and as a result, it is very difficult for a human to interpret it. You should see a screen that looks like this: Enter where it says Enter request URL here and press the Send button. Let's start with loading some web pages you are probably familiar with. We'll take advantage of these features throughout the course of this book, but we won't need most of them to make some simple requests. You can think of Postman as a specialized web browser that allows a little more manual control and has more buttons and switches as a result. It is fairly easy to make an HTTP request with postman. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |