Skip to main content

Go


Request


package main

import (
"fmt"
"net/http"
"io/ioutil"
)

func main() {

url := "api.italiakit.it/api/v1/regioni/molise"
method := "GET"

client := &http.Client {
}
req, err := http.NewRequest(method, url, nil)

if err != nil {
fmt.Println(err)
return
}
token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYzOWEwODBkMTc1YjljO
DMyZjBlODBiMyIsImlhdCI6MTY3MTAzODk4OSwiZXhwIjoxNjczNjMwOTg5fQ.a2pQ
mUI8nr_m3XGzH8C2d67vnU313W0bOhrMBDqUpXA"

req.Header.Add("Authorization", "Bearer " + token)

res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

Response

{
"data" : [
{
"_id":"638c8be8084784ddedad6ca4",
"name":"MOLISE",
"wiki":"https://it.wikipedia.org/wiki/Molise",
"province":[{
"id":"CB",
"name":"CAMPOBASSO",
"info":{
"population":"221238",
"area_km":"2925,41",
"density":"76",
"wiki":"https://it.wikipedia.org/wiki/Provincia_di_Campobasso"
},
"comuni":[
{
"id":"35",
"nome":"ACQUAVIVA COLLECROCE",
"cod":{
"cod_ente":"3140190010",
"cod_istat":"070001",
"cod_catastale":"A050"
},
"contact":{
"email":"collecroce@kruc.it",
"pec":"comune.acquavivacollecrocecb@legalmail.it",
"tel":"+39 0875/970128",
"fax":"+39 0875/970270"
},
"cap":"86030"
},
{
"id":"501",
"nome":"BARANELLO",
"cod":{
"cod_ente":"3140190020",
"cod_istat":"070002",
"cod_catastale":"A616"
},
"contact":{
"email":"comunedibaranello.cb@virgilio.it",
"pec":"comune.baranellocb@legalmail.it",
"tel":"+39 0874 460406",
"fax":"+39 0874 460828"
},
"cap":"86011"
}...]...}
]
}
}