These are chat archives for gin-gonic/gin

25th
Jun 2016
Armando Leon
@manofthelionarmy
Jun 25 2016 08:53
Hi everyone, I'm very new to golang and I'm very new to gin. I'm very confused on how to get POST to work. I keep getting 404 not found.
Here's my code
Armando Leon
@manofthelionarmy
Jun 25 2016 09:00

func formPost(c *gin.Context) {
message := c.PostForm("message")
nick := c.DefaultPostForm("nick", "anonymous")
c.JSON(200, gin.H{
"status": "posted",
"message": message,
"nick": nick,
})
}

func post(c *gin.Context) {
id := c.Query("id")
page := c.DefaultQuery("page", "0")
name := c.PostForm("name")
message := c.PostForm("message")

fmt.Printf("id: %s; page: %s; name: %s; message: %s", id, page, name, message)

}
func main() {
router := gin.Default()

router.POST("/form_post", formPost)
router.POST("/post", post)
router.Run(":8080")

}

Sami Koskinen
@svkoskin
Jun 25 2016 11:38
what kind of requests you are sending?
Armando Leon
@manofthelionarmy
Jun 25 2016 16:56
I'm sorry, but I'm barely getting use to this jargon but I'll try my best. Isn't POST my request? The thing is that I don't have a resource I'm posting too. And I was wondering how I can use POST without the terminal and how to use POST without generating a 404.
Ousmane Traore
@otraore
Jun 25 2016 21:14
What are you using to send your request?
Are you using any http client?
You were likely getting a 404 because you were probably using the browser (GET) request which isn’t defined
Armando Leon
@manofthelionarmy
Jun 25 2016 21:19
I wasn't us
Ousmane Traore
@otraore
Jun 25 2016 21:19
huh?
Armando Leon
@manofthelionarmy
Jun 25 2016 21:20
I'm sorry. I wasn't using any http client, but I was using the local host
Ousmane Traore
@otraore
Jun 25 2016 21:20
Oh that’s why. Well you can use any http client.
There are terminal ones and GUI ones. I personally use Postman
You can get it as a chrome extension or a native app. I personally recommend native app.
Armando Leon
@manofthelionarmy
Jun 25 2016 21:23
Oh, so then I would POST to that?
Ousmane Traore
@otraore
Jun 25 2016 21:24
You would use the http client to send a POST request.
Like this
Armando Leon
@manofthelionarmy
Jun 25 2016 21:24
Do you know where I can find any documentation or open source code that give examples of doing so?
Ousmane Traore
@otraore
Jun 25 2016 21:25
If you want I can show you how to do it over team viewer? Or I can try to find a video for you.
Have you downloaded postman?
Armando Leon
@manofthelionarmy
Jun 25 2016 21:27
I think a video would be nice to rely on in the future in case I forget a concept. Also, thank you for all your help so far!! I appreciate it.
Ousmane Traore
@otraore
Jun 25 2016 21:27
My pleasure
Armando Leon
@manofthelionarmy
Jun 25 2016 21:27
I'm going to right now. I just got home.
Ousmane Traore
@otraore
Jun 25 2016 21:28
Once you do so it will be easier to explain. Tell me when you're finished installing it.
Armando Leon
@manofthelionarmy
Jun 25 2016 21:34
It finished installing
Ousmane Traore
@otraore
Jun 25 2016 21:35
I think we should continue in private chat before we fill this one up.