Skip to content

Howdy-admoll/Auth-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Auth-API

Creating an Authentication API with Golang

GoDoc

Installation

You need to install Go on your PC or MacOS and set your Go workspace first

  • The first need Go installed (Latest Stable version is awesome)

Getting Started

  • To get started, Create a new project then, Create a new file called main.go and enter the following starter code:
package main
import (
  "fmt"
  "net/http"
  "github.com/gin-gonic/gin"
)

POST and GET methods

  • To be able to handle GET and POST requests, we create a GetMethod and PostMethod:
func PostMethod(c *gin.Context) {
  fmt.Println("\napi.go 'PostMethod' called")
  message := "PostMethod called"
  c.JSON(http.StatusOK, message)
}
func GetMethod(c *gin.Context) {
  fmt.Println("\napi.go 'GetMethod' called")
  message := "GetMethod called"
  c.JSON(http.StatusOK, message)
}

Main function

  • We need to create a Gin router for handling all the requests:
func main() {
  router := gin.Default()
}
  • Following this up, we add in the GetMethod and PostMethod:
func main() {
  router := gin.Default()
router.POST("/", PostMethod)
  router.GET("/", GetMethod)
}

About

How to create a basic Go API using Gin. then, how to create an authentication app and test it with ngrok.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages