Code Monkey home page Code Monkey logo

aloja's Introduction

aloja - little opinionated framework for plain http.Handlers

This framework provide convenience for the usual suspects when developing RESTful APIs or Web Applications.

It uses mainstream and common utilities and it is heavily opinionated with focus to alleviate repetitive tasks.

Features

In this release, we have:

  • Fast routing (by way of httptreemux)
  • Zero downtime restarts through endless
  • Per request Context (provided by httpcontext)
  • Middleware (gently managed by alice)
  • Named params
  • Serve static pages
  • Serve http.Templates
  • Some middleware: -- compression -- logs -- cors

Installation

go get github.com/jllopis/aloja

Quick sample

The framework lacks documentation. The use is something like this:

package main

import (
	"fmt"
	"net/http"
	"testing"

	"github.com/jllopis/aloja"
	"github.com/jllopis/aloja/mw"
)

func indexHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Welcome!")
}

func sayHello(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello little grasshoper!")
}

func sayHelloName(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello %s!", aloja.Params(r).ByName("name"))
}

func main() {
	// New server on port 8888
	server := New().Port("8888")

	// Use CORS Handler in every request
	server.AddGlobal(mw.CorsHandler)

	// Log every request
	server.AddGlobal(mw.LogHandler)

	// handler on main route
	server.HandleFunc("GET", "/", indexHandler)

	// Create a subrouter on branch /v1
	r1 := server.NewSubrouter("/v1")

	// Accept compression on this subrouter
	r1.Use(mw.CompressHandler)

	// Say hello!
	r1.Get("/hello", http.HandlerFunc(sayHello))

	// Say hello!
	r1.Get("/hello/:name", http.HandlerFunc(sayHelloName))

	// Run rabbit run!
	server.Run()
}

aloja's People

Contributors

jllopis avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

fvbock

aloja's Issues

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.