Skip to content

Latest commit

History

History
44 lines (36 loc) 路 722 Bytes

README.md

File metadata and controls

44 lines (36 loc) 路 722 Bytes

Util 馃З JSON

Send JSON Responses

Usage :

Import it to your code 馃敔

    import (
        alfJSON "github.com/PiterWeb/Alf-Router/utils/json"
    )

Create your custom Struct or a Map

    type MyCustomResponse struct {
        Message string
    }

Start sending JSON across your API Endpoints

    err := alf.App(&alf.AppConfig{
    	Port: "3000",
    	Routes: alf.CreateRouter([]alf.Route{
    		{
				Path: "/api",
				Handle: func(ctx *alf.Ctx) error {

					_, err := alfJSON.JSON(ctx, MyCustomResponse{
                        Message: "Hello World",
                    })

					return err
				},
				Method: "get",
			},
    	}),
    })

	if err != nil {
		panic(err)
	}