GithubHelp home page GithubHelp logo

dandugula / luddite.v2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from spirentorion/luddite.v2

0.0 2.0 0.0 1.11 MB

A golang package that provides a micro-framework for RESTful web services

License: MIT License

Makefile 0.56% Go 99.44%

luddite.v2's Introduction

Luddite Service Framework Package, Version 2

Luddite is a golang package that provides a micro-framework for RESTful web services. It is built around extensible, pluggable middleware layers and includes a flexible resource abstraction that makes it easy to implement services that comply with the Orion REST API Standards.

To run the example service:

$ make all
$ cd example
$ ./example -c config.yaml

Request Handling

The basic request handling built into luddite combines CORS, tracing, logging, metrics, profiling, and recovery actions.

Tracing generates a unique request id and optionally records traces to a file or persistent backend. The framework currently uses v2 of the trace package.

Logging is based on logrus. A service log is established for general use. An access log is maintained separately. Both use structured JSON logging.

Prometheus metrics provide basic request/response stats. By default, the metrics endpoint is served on /metrics.

The standard net/http/pprof profiling handlers may be optionally enabled. These are served on /debug/pprof.

Recovery handles panics that occur in resource handlers and optionally includes stack traces in 500 responses.

Request Middleware

Currently, luddite registers two middleware handlers for each service:

  • Negotiation: Performs JSON (default) and XML content negotiation based on HTTP requests' Accept headers.

  • Version: Performs API version selection and enforces the service's min/max supported version constraints. Makes the selected API version available to resource handlers as part of the request context.

Implementations are free to register their own additional middleware handlers in addition to these two.

Resource Abstraction

Generally, each resource falls into one of two categories.

  • Collection: Supports GET, POST, PUT, and DELETE.
  • Singleton: Supports GET and PUT.

The framework defines several interfaces that establish its resource abstraction. For collection-style resources:

  • CollectionLister returns all elements in response to GET /resource.
  • CollectionCounter returns a count of its elements in response to GET /resource/all/count.
  • CollectionGetter returns a specific element in response to GET /resource/:id.
  • CollectionCreator creates a new element in response to POST /resource.
  • CollectionUpdater updates a specific element in response to PUT /resource/:id.
  • CollectionDeleter deletes a specific element in response to DELETE /resource/:id. It may also optionally delete the entire collection in response to DELETE /resource
  • CollectionActioner executes an action in response to POST /resource/:id/:action.

And for singleton-style resources:

  • SingletonGetter returns a response to GET /resource.
  • SingletonUpdater is updated in response to PUT /resource.
  • SingletonActioner executes an action in response to POST /resource/:action.

Routes are automatically created for resource handler types that implement these interfaces. However, since luddite is a framework, implementations retain substantial flexibility to register their own routes if these are not sufficient.

Resource Versioning

The framework allows implementations to support multiple API versions simultaneously. In addition to API version selection via middleware, the framework also allows for version-specific resource registration.

Typically, implementations define a separate resource handler type for each API version. The routes for each type are registered in a version-specific router. Since route lookup occurs after version negotiation, each router is free to handle requests without further consideration of API version.

luddite.v2's People

Contributors

avmedrano avatar bandrews-spirent avatar bsilverman avatar dandugula avatar djoyner avatar ericgreen avatar lwheat avatar mourad avatar peterkellydev avatar poksh avatar ronanjs avatar stanislavbelyakov avatar vasusankaran avatar

Watchers

 avatar  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.