GithubHelp home page GithubHelp logo

bonyaroslav / jsonrest-go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from farzad-jalali/jsonrest-go

0.0 0.0 0.0 112 KB

A minimal framework for RESTful web applications in Go.

License: The Unlicense

Makefile 2.92% Go 97.08%

jsonrest-go's Introduction

jsonrest-go

CircleCI Go Report Card GoDoc go.dev

Package jsonrest implements a microframework for writing RESTful web applications.

Endpoints are defined as:

func(ctx context.Context, req *jsonrest.Request) (interface{}, error)

If an endpoint returns a value along with a nil error, the value will be rendered to the client as JSON.

If an error is returned, it will be sanitized and returned to the client as json. Errors generated by a call to jsonrest.Error(status, code, message) will be rendered as-is to the client, along with the given HTTP status code. Any other errors will be obfuscated to the caller (unless router.DumpError is enabled).

Example:

func main() {
    r := jsonrest.NewRouter()
    r.Use(logging)
    r.Get("/", hello)
}

func hello(ctx context.Context, req *jsonrest.Request) (interface{}, error) {
    return jsonrest.M{"message": "Hello, world"}, nil
}

func logging(next jsonrest.Endpoint) jsonrest.Endpoint {
    return func(ctx context.Context, req *jsonrest.Request) (interface{}, error) {
        start := time.Now()
        defer func() {
            log.Printf("%s (%v)\n", req.URL().Path, time.Since(start))
        }()
        return next(ctx, req)
    }
}

Contributing

Review the contributing guidelines.

jsonrest-go's People

Contributors

johngibb avatar mbranch avatar raycchan avatar thoeni avatar jeffreylo avatar richcq avatar mathildathompson 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.