Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get parameters #18

Closed
gallart opened this issue Jan 18, 2019 · 1 comment
Closed

Get parameters #18

gallart opened this issue Jan 18, 2019 · 1 comment

Comments

@gallart
Copy link

gallart commented Jan 18, 2019

Hi,

How to extract data from POST requests ?

Thanks

@nbari
Copy link
Owner

nbari commented Jan 18, 2019

Hi @gallart here is a small example, but may be worth for you to check the net/http docs https://golang.org/pkg/net/http/, violetear doesn't modify/changes the *http.Request behavior:

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/nbari/violetear"
)

func handler(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	x := r.Form.Get("foo")
	fmt.Println(x)
}

func main() {
	router := violetear.New()
	router.HandleFunc("*", handler, "POST") // catchall request but only accept  POST method
	log.Fatal(http.ListenAndServe(":8080", router))
}

Then from the command line:

curl -d "foo=bar" -X POST http://localhost:8080

@nbari nbari closed this as completed Jan 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants