How to Get the Gender of a First Name using Go

Cloudmersive
2 min readDec 5, 2022

Perhaps the most important determination of any person’s gender is the way that person chooses to outwardly identify themselves. Without access to that user-supplied information, however, much can be determined instead from first names and the cultures they originate from. Our “Get Gender from First Name” API takes both name & country of origin into account to determine the gender most likely associated with a given name, and it supplies that gender as a string value in response. The request format for this API can be structured following the below JSON example (or XML equivalent):

{
"FirstName": "string",
"CountryCode": "string"
}

Below, complementary ready-to-run Golang code examples have been provided from our API documentation page to help you structure your API call with ease. To complete your API call, you’ll need a free-tier Cloudmersive API key at minimum, which you can get by registering a free account on our website (free-tier keys yield a limit of 800 API calls per month; no financial commitments are incurred upon reaching this limit).

package main

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

func main() {

url := "https://api.cloudmersive.com/validate/name/get-gender"
method := "POST"

payload := strings.NewReader(`{
"FirstName": "<string>",
"CountryCode": "<string>"
}`)

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

if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")

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))
}

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.