课程: Go Essentials: Concurrency, Connectivity, and High-Performance Apps
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
HTTP calls - Go教程
课程: Go Essentials: Concurrency, Connectivity, and High-Performance Apps
HTTP calls
- [Instructor] A common way of communicating between processes, is calling APIs. One of the most common API is called the REST API. It is JSON and serialization over HTTP. The net dot HTTP package, will cover all of your needs. It contains both an HTTP client, and as we'll see later, also an HTTP server. So let's have a look. First we're going to make a GET request. So I'm using the net http package. And then I'm getting a response by calling HTTP get on httpbin.org/get. httpbin.org is a site for testing your HTTP client. I'm checking if there is an error, if not I'm deferring closing of the response body, and I'm going to copy to the standard output whatever came from the response. Let's run it. And we see that HTTP being sent us the arguments, the headers, et cetera, et cetera. If you want to make an HTTP POST request, we can use the POST method. And this time we are going to combine it with some JSON data.…