Execute sequentially http.Get requets

Hi guys I’ve been googling for a while and I don’t find the answer to this question: Are http request synchronous or asynchronous? All information points to say they’re concurrent, but I don’t get what this means in this context, so let put a little example: Suppose I have a bunch of structures that I want to fill with the response from two different http calls and the way I need this(this is a simplified example what I’m trying to do really needs it to be executed that way) is for examle:

type person struct {
    name string
    age  int
var ids interface{}
var names interface{}
idsToSearch := [1,2,3]
var personList [] interface {}
for _, i := range idsToSearch{
   resp, err = http.Get("webServiceWithId's", i)
   defer resp.Body.Close()
   dec := json.NewDecoder(r.Body)
   for _, item := range ids.id {
         var rPerson person
         person.id = item.id
         resp, err = http.Get("webServiceWithNames")
         defer resp.Body.Close()
         dec := json.NewDecoder(r.Body)
         for _, name := range names.id {
             person.name = name.name
        personList.append(personList, person)

I don’t know if this is clear enough, what I’m asking is can I concatenate two(or more) request in a loop so the second one uses first’s response and the program waits until the second has finished to keep executing the loop and make a new fist type petition?

Hi. Yes. Calling a Get will halt that goroutine until it returns a result and then it will continue executing.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.