Giter Site home page Giter Site logo

hapi's Introduction

HAPI - is a Human API

HAPI is a universal http handler allows used any functions how http handlers. Current version has only one wrapper over echo web framework, in the future plans to create interfaces to the many other frameworks.

INSTALL

go get github.com/sg3des/hapi

USAGE

func main() {
	e := echo.New()
	// some actions...

	h := hapi.New(e)
	h.POST("/some/path", handler)
}

type reqData struct {
	Something string
	Other int
	// ... any other fields
}

type respData struct {
	ID uint
	Name string
	Text string
	// ... etc ...
}

// handler receivs specified strcture filled by JSON or Form data from request
// returns data convert to the JSON and returned how response
func handler(data yourData) respData {
	// ... something actions

	return respData{ID: 123, Name: "response"}
}

HAPI support many cases of incoming arguments: parse whole request to struct, receive files from multipart form data, multiple arguments can be filled from form data or url values, etc

If function returns:

- structs returns how JSON
- string or bytes write as it is to the response body
- error returns how error
- int - transform to the status code

hapi's People

Contributors

sg3des avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.