GithubHelp home page GithubHelp logo

jmptrader / iris-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kataras/iris

0.0 1.0 0.0 114 KB

A very minimal but flexible golang web application framework, providing a robust set of features for building single & multi-page, web applications.

License: MIT License

Go 99.92% Batchfile 0.08%

iris-1's Introduction

Iris Web Framework

[![Build Status](https://travis-ci.org/kataras/iris.svg)](https://travis-ci.org/kataras/iris) [![GoDoc](https://godoc.org/github.com/kataras/iris?status.svg)](https://godoc.org/github.com/kataras/iris) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/kataras/iris?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

Iris is a very minimal but flexible web framework written in go, providing a robust set of features for building single & multi-page, web applications.

Table of Contents

Install

$ go get github.com/kataras/iris

Principles of iris

  • Easy to use

  • Robust

  • Simplicity Equals Productivity. The best way to make something seem simple is to have it actually be simple. iris's main functionality has clean, classically beautiful APIs

Introduction

The word iris means "rainbow" in Greek. Iris was the name of the Greek goddess of the rainbow. Iris is a very minimal but flexible golang http middleware & standalone web application framework, providing a robust set of features for building single & multi-page, web applications.

package main

import "github.com/kataras/iris"

func main() {
	iris.Get("/hello", func(r *iris.Renderer) {
		r.HTML("<b> Hello </b>")
	})
	iris.Listen(8080)
}

Features

Only explicit matches: With other routers, like http.ServeMux, a requested URL path could match multiple patterns. Therefore they have some awkward pattern priority rules, like longest match or first registered, first matched. By design of this router, a request can only match exactly one or no route. As a result, there are also no unintended matches, which makes it great for SEO and improves the user experience.

Parameters in your routing pattern: Stop parsing the requested URL path, just give the path segment a name and the router delivers the dynamic value to you. Because of the design of the router, path parameters are very cheap.

Perfect for APIs: The router design encourages to build sensible, hierarchical RESTful APIs. Moreover it has builtin native support for OPTIONS requests and 405 Method Not Allowed replies.

Compatible: At the end the iris is just a middleware which acts like router and a small simply web framework, this means that you can you use it side-by-side with your favorite big and well-tested web framework. Iris is fully compatible with the net/http package.

Miltiple servers : Besides the fact that iris has a default main server, which only created only if you call any global function (e.x iris.Get). You can declare a new iris using the iris.New() func. server1:= iris.New(); server1.Get(....); server1.Listen(9999)

API

Use of GET, POST, PUT, DELETE, HEAD, PATCH & OPTIONS

package main

import (
	"github.com/kataras/iris"
	"net/http"
)

func main() {
	iris.Get("/home", testGet)
	iris.Post("/login",testPost)
	iris.Put("/add",testPut)
	iris.Delete("/remove",testDelete)
	iris.Head("/testHead",testHead)
	iris.Patch("/testPatch",testPatch)
	iris.Options("/testOptions",testOptions)

	iris.Listen(8080)
}

//iris is fully compatible with net/http package
func testGet(res http.ResponseWriter, req *http.Request) {
	//...
}

func testPost(c *iris.Context) {
	//...
}

func testPut(r *iris.Renderer) {
	//...
}

func testDelete(c *iris.Context, r *iris.Renderer) {
	//...
}
//and so on....

Named Parameters

Named parameters are just custom paths to your routes, you can access them for each request using context's c.Param("nameoftheparameter") or iris.Param(request,"nameoftheparam"). Get all, as pair (map[string]string) using c.Params() or iris.Params(request)

By default the :name is matched to any word, you can use custom regex using parenthesis after the parameter example: /user/:name([a-z]+) this will match the route only if the second part of the route after /user/ is a word which it's letters are lowercase only.

No limit on how long a path can be.

Usage:

package main

import "github.com/kataras/iris"

func main() {
	// MATCH to /hello/anywordhere
	// NOT match to /hello or /hello/ or /hello/anywordhere/something
	iris.Get("/hello/:name", func(c *iris.Context) {
		name := c.Param("name")
		c.Write("Hello " + name)
	})

	// MATCH to /profile/kataras/friends/1
	// NOT match to /profile/ , /profile/kataras ,
	// /profile/kataras/friends,  /profile/kataras/friends ,
	// /profile/kataras/friends/string , /profile/anumb3r/friends/1
	iris.Get("/users/:fullname([a-zA-Z]+)/friends/:friendId(int)",
		func(c *iris.Context, r *iris.Renderer){
			name:= c.Param("fullname")
			friendId := c.ParamInt("friendId")
			r.HTML("<b> Hello </b>"+name)
		})

	iris.Listen(8080)
	//or log.Fatal(http.ListenAndServe(":8080", iris))
}

Note: Since this router has only explicit matches, you can not register static routes and parameters for the same path segment. For example you can not register the patterns /user/new and /user/:user for the same request method at the same time. The routing of different request methods is independent from each other.

Third Party Middleware

The iris is re-written in order to support all middlewares that are already exists for Negroni middleware

Here is a current list of compatible middlware.

Middleware Author Description
RestGate Prasanga Siripala Secure authentication for REST API endpoints
Graceful Tyler Bunnell Graceful HTTP Shutdown
secure Cory Jacobsen Middleware that implements a few quick security wins
JWT Middleware Auth0 Middleware checks for a JWT on the Authorization header on incoming requests and decodes it
binding Matt Holt Data binding from HTTP requests into structs
logrus Dan Buch Logrus-based logger
render Cory Jacobsen Render JSON, XML and HTML templates
gorelic Jingwen Owen Ou New Relic agent for Go runtime
gzip phyber GZIP response compression
oauth2 David Bochenski oAuth2 middleware
sessions David Bochenski Session Management
permissions2 Alexander Rødseth Cookies, users and permissions
onthefly Alexander Rødseth Generate TinySVG, HTML and CSS on the fly
cors Olivier Poitrey Cross Origin Resource Sharing (CORS) support
xrequestid Andrea Franz Middleware that assigns a random X-Request-Id header to each request
VanGoH Taylor Wrobel Configurable AWS-Style HMAC authentication middleware
stats Florent Messa Store information about your web application (response time, etc.)

Contributors

Thanks goes to the people who have contributed code to this package, see the GitHub Contributors page.

Community

If you'd like to discuss this package, or ask questions about it, please use one of the following:

Todo

  • Complete the documents
  • Query parameters
  • Recover on panic support
  • Create examples in this repository

Licence

This project is licensed under the MIT license.

iris-1's People

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.