I ran into a little issue as I tried to POST to a Go backend using Axios but I could not get the parameters I was sending.

I was doing this:

func handleReq(w http.ResponseWriter, req *http.Request) {
	err := req.ParseForm()
	if err != nil {
	v := req.Form
	owner := req.Form.Get("owner")
	name := req.Form.Get("name")

but the two parameters I was looking for were not available. Why?

Turns out that I was assuming Axios sent the parameters using Content-Type:application/x-www-form-urlencoded but by default it’s using Content-Type:application/json.

Note: you can configure it to use application/x-www-form-urlencoded, check https://github.com/axios/axios#using-applicationx-www-form-urlencoded-format

This means that to access the parameters I need to decode them using json.Decoder.

Here is some sample code that does the trick:

type myData struct {
	Owner string
	Name  string

func handleAddNewRepo(w http.ResponseWriter, req *http.Request) {
	decoder := json.NewDecoder(req.Body)

	var data myData
	err := decoder.Decode(&data)
	if err != nil {

	owner := data.Owner
	name := data.Name

Did you know?

I have 7 premium training programs that will transform you, quickly, into an excellent Node/React/JS/Vue/Next.js/Svelte developer. Choose your own adventure. Practical lessons to learn the 80% of the things that you need to know, in 20% of the time!

⬇️ ⬇️ ⬇️

Check out all my courses now!

⬆️ ⬆️ ⬆️