Skip to content

agusmunioz/ape

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ape

Ape provides a Handler that encapsulates HTTP response management for JSON format.

package main

import (
	"github.com/agusmunioz/ape"
	"github.com/gorilla/mux"
	"log"
	"net/http"
)

type Article struct {
   Id     string   `json:"id"`
   Title  string   `json:"title"`
}

//GetArticles returns business objects in an ape response, no json encoding is need it.
func GetArticles(r *http.Request) ape.Response {
   articles:= []Article{
                 {Id: "1234", Title: "An interesting article"},
		 {Id: "5678", Title: "Another interesting article"},
		} 
   return ape.NewOk(articles)
}

func main() {
   r := mux.NewRouter()
   r.Handle("/articles", ape.Handler(GetArticles)).Methods(http.MethodGet)
   log.Fatal(http.ListenAndServe(":8080", r))
}

About

Go handler for JSON request/response

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages