A lightweight RESTful web framework for Go

Goweb

A lightweight RESTful web framework for Go.

Goweb A lightweight RESTful web framework for Go.

wercker status

Who uses Goweb?

  • "Using Goweb has greatly simplified the creation, maintenance, and consistency of several of our internal services, allowing us to focus our effort on the underlying behavior of the services themselves." Derek Buitenhuis, Vimeo
  • "We are actively developing with Goweb to implement the REST api in-front of a neural network application" Jon McMillan, MCN Healthcare
  • "We are developing an API on top of Goweb that will power our platform as well as allow customers to access our data via a REST API." Robert Mulley, CB Insights

Are you using Goweb?

We are looking to put together a list of companies / people that are using Goweb. If you would like to help promote Goweb, and be included in the list, please comment on our issue and we'll get it going. Thanks.

Get started

  • To install, run go get github.com/stretchr/goweb
  • Import the package as usual with import "github.com/stretchr/goweb" in your code.
  • Look at the example_webapp project for some ideas of how to get going
  • Read the Goweb API Documentation
  • To update to the latest version of goweb, just run go get -u github.com/stretchr/goweb

Features

  • Drastically improved path matching
  • Cleaner interface for responding (e.g. goweb.API.RespondWithData, and goweb.Respond.WithRedirect)
  • More control over standard response object for API responses
  • Cleaner RESTful interface design
    • Default OPTIONS implementation that informs clients what methods the controller exposes
  • Easily publish static files as well as code driven output
  • Much easier to write testable code
  • Better package structure
  • Modular design, making adding new stuff easy
  • Handler mechanism to easily add pre and post handlers to certain requests
  • Uses stretchr/codecs package allowing better support for multiple formats
  • Easily match paths using Regex instead
  • Better error management
  • Performance improvements from Goweb 1

Interesting articles

People who use Goweb also use

  • Gomniauth - Authentication package (OAuth2 etc.)

Requirements

  • Goweb runs on Go 1.1

Contributing

Please feel free to submit issues, fork the repository and send pull requests. Be sure to check out our development practices before you get going.

When submitting an issue, we ask that you please include steps to reproduce the issue so we can see it on our end also!

Licence

Copyright (c) 2012 - 2013 Mat Ryer and Tyler Bunnell

Please consider promoting this project if you find it useful.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Owner
Stretchr, Inc.
Tame your unstructured data - We <3 open-source.
Stretchr, Inc.
Comments
  • Collect a list of people using Goweb

    Collect a list of people using Goweb

    We are looking to put together a list of companies / people that are using Goweb. If you would like to help promote Goweb, and be included in the list, please comment on this issue and we'll get it going.

    Thanks, Goweb team

  • Why not use Goweb?

    Why not use Goweb?

    Please leave a comment and tell us:

    • Why you chose not to use Goweb
    • Did it lack something you needed?
    • Do you think the project would benefit from an additional capability?
  • Proposed change to HTTP Methods

    Proposed change to HTTP Methods

    Since POST should create resources, I propose we change the way Goweb maps the RESTful interfaces in the following way.

    These will stay the same:

    RestfulReader Read = GET /path/{id}
    RestfulManyReader ReadMany = GET /path
    RestfulCreator Create = POST /path
    RestfulDeletor Delete = DELETE /path/{id}
    RestfulManyDeleter DeleteMany = DELETE /path
    (OPTIONS and HEAD will remain the same)    
    

    These will change from:

    RestfulUpdater Update = PUT /path/{id}
    RestfulReplacer Replace = POST /path/{id}
    RestfulManyUpdater UpdateMany = PUT /path
    

    to

    RestfulUpdater Update = PATCH /path/{id}
    RestfulReplacer Replace = PUT /path/{id}
    RestfulManyUpdater UpdateMany = PATCH /path
    
    • Since this will break existing interfaces, it's an important thing to carefully consider the consequences.
  • Don't envelop data in responses by default

    Don't envelop data in responses by default

    HI,

    maybe I'm missing something but I can't find any obvious way to turn off enveloping of data in responses (http://godoc.org/github.com/stretchr/goweb/responders#pkg-constants)

    Data enveloping should not be default (http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#envelope) but rather let the API creator decide whether to support it or not.

  • MapController, MapStaticFile, MapStatic don't accept MatcherFuncs

    MapController, MapStaticFile, MapStatic don't accept MatcherFuncs

    It seems slightly odd that Map, MapBefore, and MapAfter all accept MatcherFuncs as additional parameters, while MapController, MapStaticFile, and MapStatic don't.

    Use Case:

    I am writing a RESTful API. I want a different controller to be called for different types of Accept headers. When the Accept header includes 'text/html', I want to display my generated godoc documentation (using MapStatic or MapStaticFile). When the Accept header includes 'application/-+', I want to run the an API controller that runs the correct version.

    I want to do this by essentially passing a MatcherFunc to the MapController, MapStatic, etc methods which checks the Accept header against a list of acceptable values. But currently, they cannot accept MatcherFuncs.

    I'm forking the repo and tossing that in myself (because it's easy), and ... will probably make a pull request after I get it working, because ... that's the right thing to do? I think? Goodness, I'm too used to bugzilla and attaching patches. I feel old.

    [edit] If there's a better way to do this, please let me know. I haven't been doing this very long, but from what I've seen, that seems to be the best route. [/edit]

  • security bug: static file serving arbitrary file/source

    security bug: static file serving arbitrary file/source

    Hi, when a server comes up with a static serving directory. from client side it is able to access arbitrary file using relative path.

    for example: my server is serving /static for static files, i can get /etc/passwd by requesting /static/../../../../../../etc/passwd

    $ telnet localhost 9123
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    GET /static/../../../../../../etc/passwd HTTP/1.0
    
    HTTP/1.0 200 OK
    Accept-Ranges: bytes
    Content-Length: 1234
    Content-Type: text/plain; charset=utf-8
    Last-Modified: Sat, 01 Aug 2012 05:13:28 GMT
    X-Custom-Header: Goweb
    Connection: close
    Date: Wed, 05 Jun 2013 04:30:46 GMT
    
    root:x:0:0:root:/root:/bin/bash
    ........
    
  • codecs: Cannot call PublicData(map[string]int) because it does not implement codecs.Facade (i.e. needs PublicData method) and is not a Data object.

    codecs: Cannot call PublicData(map[string]int) because it does not implement codecs.Facade (i.e. needs PublicData method) and is not a Data object.

    A simple REST controller with a method:

    func (ctrl _MyController) ReadMany(ctx context.Context) error { var Things []_Thing thing := new(Thing) thing.Id = "A" thing.Text = "A Thing!" Things = append(Things, thing) return goweb.API.RespondWithData(ctx, Things) }

    Request: GET /api/my

    Leads to the following in the console:

    2013/06/12 10:53:32 http: panic serving 127.0.0.1:49779: codecs: Cannot call PublicData([]_controllers.Thing) because it does not implement codecs.Facade (i.e. needs PublicData method) and is not a Data object. goroutine 11 [running]: net/http.func·007() /usr/local/go/src/pkg/net/http/server.go:1022 +0xac github.com/stretchrcom/codecs.publicData(0x274fe0, 0xc200151c60, 0x0, 0x0, 0x6e7a30, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/codecs/facade.go:106 +0x2fe github.com/stretchrcom/codecs.PublicData(0x274fe0, 0xc200151c60, 0x0, 0x1, 0x2842a0, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/codecs/facade.go:63 +0x42 github.com/stretchrcom/goweb/responders.(_GowebAPIResponder).Respond(0xc2000eb7e0, 0xc2000dc7e0, 0xc200157c40, 0xc8, 0x274fe0, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/responders/goweb_api_responder.go:130 +0xa8 github.com/stretchrcom/goweb/responders.(_GowebAPIResponder).RespondWithData(0xc2000eb7e0, 0xc2000dc7e0, 0xc200157c40, 0x274fe0, 0xc200151c60, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/responders/goweb_api_responder.go:155 +0x6c project/api/controllers.(_MyController).ReadMany(0xc2000008a8, 0xc2000dc7e0, 0xc200157c40, 0x1, 0x1, ...) /Users/alex/Documents/Work/sources/backend/src/project/api/controllers/poi.go:37 +0x171 github.com/stretchrcom/goweb/controllers.RestfulManyReader.ReadMany·fm(0xc2000dc7e0, 0xc200157c40, 0x0, 0x0) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/handlers/mapping.go:234 +0x52 github.com/stretchrcom/goweb/handlers.(_PathMatchHandler).Handle(0xc2000ebf00, 0xc2000dc7e0, 0xc200157c40, 0x1, 0x0, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/handlers/path_match_handler.go:137 +0x38 github.com/stretchrcom/goweb/handlers.Pipe.Handle(0xc200100600, 0x17, 0x20, 0xc2000dc7e0, 0xc200157c40, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/handlers/pipe.go:61 +0x121 github.com/stretchrcom/goweb/handlers.(_Pipe).Handle(0xc200151800, 0xc2000dc7e0, 0xc200157c40, 0xdd301, 0x0, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/handlers/default_error_handler.go:0 +0x9a github.com/stretchrcom/goweb/handlers.Pipe.Handle(0xc20014d690, 0x3, 0x3, 0xc2000dc7e0, 0xc200157c40, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/handlers/pipe.go:61 +0x121 github.com/stretchrcom/goweb/handlers.(_HttpHandler).ServeHTTP(0xc2001468c0, 0xc2001544c0, 0xc200157bd0, 0xc20014b680) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/handlers/http_handler.go:67 +0xac net/http.serverHandler.ServeHTTP(0xc200147820, 0xc2001544c0, 0xc200157bd0, 0xc20014b680) /usr/local/go/src/pkg/net/http/server.go:1517 +0x16c net/http.(_conn).serve(0xc2000e26c0) /usr/local/go/src/pkg/net/http/server.go:1096 +0x765 created by net/http.(*Server).Serve /usr/local/go/src/pkg/net/http/server.go:1564 +0x266

  • Design views in Goweb

    Design views in Goweb

    Views are a key part of web development, and if you're not building a data API you will likely be managing views in some way within Goweb.

    We would like to implement a solution for new projects that will make managing views as easy as it is in Ruby on Rails.

    Initial thinking:

    • Must be easy to render a view
    • View rendering service must be interchangeable; if people want to use another templating framework, they should easily be able to
    • Helpers for common stuff (like building URLs etc.)
    • Can a controller automatically be mapped using reflection? So /controller/action would map to the action method on the controller class. E.g. /people/new would map to PeopleController and call method New.
  • Should the goweb `import` path include v2?

    Should the goweb `import` path include v2?

    Should the Goweb import path include the version number?

    i.e.

    import (
      "github.com/stretchrcom/goweb/v2"
    )
    

    The namespace would still be goweb allowing clean code.

  • Example for injecting database into context

    Example for injecting database into context

    Is there a way to maintain a database connection (using https://github.com/vmihailenco/redis/tree/master/v2 for example) and then inject access to it into the context so that each request can use the connection (thread-safely) without having to reconnect?

    If you have an example of the correct way of doing this, it'd be greatly appreciated.

  • RestfulManyUpdater has wrong mapping

    RestfulManyUpdater has wrong mapping

    In the docs (http://godoc.org/github.com/stretchr/goweb/controllers#RestfulManyUpdater), the RestfulManyUpdater has this mapping:

    GET /resources/{id}

    Which is not correct and should instead be:

    PUT /resources

    I haven't check if it is only an error in documentation or if the implementation is incorrect also

  • Why aren't dotted values allowed for resource ids?

    Why aren't dotted values allowed for resource ids?

    goweb seems to always assume that a . means a file extension - but when using a controller this doesn't really make sense.

    e.g. DELETE /something/10.0.0.1 would call somethingController.Delete("10", ctx) - which seems really very wrong ...

  • Testing Controllers?

    Testing Controllers?

    I was looking at webcontext_test and it more or less works for me, but I noticed the note that testify/http/TestResponseWriter is deprecated. Is there a new approach that uses ResponseRecorder? I tried whipping up my own TestContext using ResponseRecorder but I didn't have much luck getting it going.

  • Figure out real status with always200

    Figure out real status with always200

    Here's a situation we've faced. We store some media objects (AWS S3 backend) and the API returns temporary redirects with timestamped signature in the URL. The resource requires our custom token-based authentication (Authorization header in request). The client-side (JS app) uses direct URLs to resources in tags like but it fails because of authentication. When using a XHR to perform authorised request the XHR follows redirect automatically (no chance to switch it off) and this one is also not an option.

    The always200=true therefore is a good way to overcome this problem. But in this case the response from the server contain http status 200 and of course an empty body (originally we send a temporary redirect). Therefore it's nearly impossible to figure out what's happening on the server (without looking into the headers of course).

    The question is would it be an expected behaviour from goweb to force to include a body, where it was not specified in cases with awlays200 to contain at least { s:REAL_STATUS} ?

  • The server's binary gets all the test flags

    The server's binary gets all the test flags

    I've noticed weird flags appear when I print the -help of my binary:

    Usage of app/bin/server: -conf="etc/config.yml": Configuration file -ip="0.0.0.0": IP address to bind server to. Example: 127.0.0.1 -port=8080: Port number to bind server to. Example: 8080 -test.bench="": regular expression to select benchmarks to run -test.benchmem=false: print memory allocations for benchmarks -test.benchtime=1s: approximate run time for each benchmark -test.blockprofile="": write a goroutine blocking profile to the named file after execution -test.blockprofilerate=1: if >= 0, calls runtime.SetBlockProfileRate() -test.cpu="": comma-separated list of number of CPUs to use for each test -test.cpuprofile="": write a cpu profile to the named file during execution -test.memprofile="": write a memory profile to the named file after execution -test.memprofilerate=0: if >=0, sets runtime.MemProfileRate -test.parallel=1: maximum test parallelism -test.run="": regular expression to select tests and examples to run -test.short=false: run smaller test suite to save time -test.timeout=0: if positive, sets an aggregate time limit for all tests -test.v=false: verbose: print additional output

    As far as I can see from:

    $ go list -f '{{join .Deps "\n"}}' github.com/stretchr/goweb | grep testing testing

    Goweb can be the reason... Any ideas how to get rid of these flags?

  • Simplified API in the future? Goweb use too many []interface{} for args

    Simplified API in the future? Goweb use too many []interface{} for args

    I'm going to use Goweb for the next project, after reading the API document I feel Goweb use too many ...interface{} for the function agrs. I give some flexible but sometime give some confusions. Why don't we just provide the most general API for the function? For example, goweb.Map should be:

    func Map(fn func(c context.Context) error, path string, methods []string, matchers []handlers.MatcherFunc) (handlers.Handler, error)
    

    or goweb.MapController should be just:

    func MapController(controller interface{}, path string) error
    

    I know this is not that importan and hard to change because you will break your old code but it still worth something! I bet that many of us love Go because the simplicity and clarity (by the lack of function overloading and something else)

    Thanks for the team for your great package!

Related tags
Flamingo Framework and Core Library. Flamingo is a go based framework for pluggable web projects. It is used to build scalable and maintainable (web)applications.
Flamingo Framework and Core Library. Flamingo is a go based framework for pluggable web projects. It is used to build scalable and maintainable (web)applications.

Flamingo Framework Flamingo is a web framework based on Go. It is designed to build pluggable and maintainable web projects. It is production ready, f

Jan 5, 2023
The jin is a simplified version of the gin web framework that can help you quickly understand the core principles of a web framework.

jin About The jin is a simplified version of the gin web framework that can help you quickly understand the core principles of a web framework. If thi

Jul 14, 2022
Lightweight web framework based on net/http.

Goweb Light weight web framework based on net/http. Includes routing middleware logging easy CORS (experimental) Goweb aims to rely only on the standa

Dec 21, 2022
Simple and lightweight Go web framework inspired by koa
Simple and lightweight Go web framework inspired by koa

VOX A golang web framework for humans, inspired by Koa heavily. Getting started Installation Using the go get power: $ go get -u github.com/aisk/vox B

Dec 14, 2022
Eudore is the core of a golang lightweight web framework.

Eudore eudore是一个golang轻量级web框架核心,可以轻松扩展成一个技术栈专用框架,具有完整框架设计体系。 反馈和交流请加群组:QQ群373278915。 Features 易扩展:主要设计目标、核心全部解耦,接口即为逻辑。 简单:对象语义明确,框架代码量少复杂度低,无依赖库。 易用

Nov 7, 2022
Dragon 🐲 🐲 🐲 is a lightweight high performance web framework with Go for the feature and comfortable develop.

Dragon project new link start dragon ab performance Dragon ?? ?? ?? is a lightweight high performance web framework with Go for the feature and comfor

Sep 6, 2022
skr: The lightweight and powerful web framework using the new way for Go.Another go the way.
skr: The lightweight and powerful web framework using the new way for Go.Another go the way.

skr Overview Introduction Documents Features Install Quickstart Releases Todo Pull Request Issues Thanks Introduction The lightweight and powerful web

Jan 11, 2022
Fastrest - fast restful framework for golang.

fastrest fast restful framework for golang. Create your app directory, like mkdir myapp; cd myapp; go mod init myapp; Create initial config.toml in a

Nov 8, 2022
A Golang restful API boilerplate based on Echo framework v4

A Golang restful API boilerplate based on Echo framework v4. Includes tools for module generation, db migration, authorization, authentication and more.

Nov 15, 2022
⚡ Rux is an simple and fast web framework. support middleware, compatible http.Handler interface. 简单且快速的 Go web 框架,支持中间件,兼容 http.Handler 接口

Rux Simple and fast web framework for build golang HTTP applications. NOTICE: v1.3.x is not fully compatible with v1.2.x version Fast route match, sup

Dec 8, 2022
Roche is a Code Generator and Web Framework, makes web development super concise with Go, CleanArch
Roche is a Code Generator and Web Framework, makes web development super concise with Go, CleanArch

It is still under development, so please do not use it. We plan to release v.1.0.0 in the summer. roche is a web framework optimized for microservice

Sep 19, 2022
A powerful go web framework for highly scalable and resource efficient web application

webfr A powerful go web framework for highly scalable and resource efficient web application Installation: go get -u github.com/krishpranav/webfr Exa

Nov 28, 2021
A powerful go web framework for highly scalable and resource efficient web application

A powerful go web framework for highly scalable and resource efficient web application

Oct 3, 2022
A web app built using Go Buffalo web framework

Welcome to Buffalo Thank you for choosing Buffalo for your web development needs. Database Setup It looks like you chose to set up your application us

Feb 7, 2022
Couper is a lightweight API gateway designed to support developers in building and operating API-driven Web projects
Couper is a lightweight API gateway designed to support developers in building and operating API-driven Web projects

Couper Couper is a lightweight API gateway designed to support developers in building and operating API-driven Web projects. Getting started The quick

Nov 18, 2022
A lightweight MVC framework for Go(Golang)

utron utron is a lightweight MVC framework in Go (Golang) for building fast, scalable and robust database-driven web applications. Features Postgres,

Nov 26, 2022
A quick and easy way to setup a RESTful JSON API

Go-Json-Rest A quick and easy way to setup a RESTful JSON API Go-Json-Rest is a thin layer on top of net/http that helps building RESTful JSON APIs ea

Jan 3, 2023