iris/_examples
Gerasimos (Makis) Maropoulos 04834484ff add a test near to the _examples/routing/basic example
Former-commit-id: 24b4ffc004f76355f6269a95ede3488fff9dfe36
2019-07-30 06:04:08 +03:00
..
apidoc/yaag Update to version 8.5.6 | Read HISTORY.md 2017-11-05 04:12:18 +02:00
authentication remove experimental-handlers examples, users should visit github.com/iris-contrib/middleware instead, let's not have duplications 2019-07-15 16:03:19 +03:00
cache resolve conflicts with current master v11.1.1 2019-07-23 19:20:07 +03:00
configuration add Context.ResponseWriter.IsHijacked to report whether the underline conn is already hijacked and a lot of cleanup and minor ws stress test example improvements 2019-02-23 07:23:10 +02:00
convert-handlers Add an example on how to use third-party handlers that are not compatible to the "next pattern" 2017-10-13 06:59:31 +03:00
cookies Cookies: Ability to set custom cookie encoders to encode the cookie's value before sent by ctx.SetCookie and ctx.SetCookieKV and cookie decoders to decode the cookie's value when retrieving from ctx.GetCookie. That was the second and final part relative to a community's question at: https://github.com/kataras/iris/issues/1018 2018-06-02 16:35:18 +03:00
file-server Updated all dependencies one by one to go.mod - Backup and remove the vendor folder entirely and update most of the examples - next commit will contain the rest of the updated 2019-07-15 07:49:04 +03:00
hello-world add Context.ResponseWriter.IsHijacked to report whether the underline conn is already hijacked and a lot of cleanup and minor ws stress test example improvements 2019-02-23 07:23:10 +02:00
hero add Context.ResponseWriter.IsHijacked to report whether the underline conn is already hijacked and a lot of cleanup and minor ws stress test example improvements 2019-02-23 07:23:10 +02:00
http_request fix https://github.com/kataras/iris/issues/1310 2019-07-25 17:08:16 +03:00
http_responsewriter examples: writing an API for the Apache Kafka: add a root handler for routes documentation to make navigation easier and add some other methods that may find them useful for request state and routes description 2018-08-05 13:51:05 +03:00
http-listening Merge branch 'master' into v11.2.0 2019-07-23 19:36:00 +03:00
miscellaneous new feature: handle different param types in the exact same path pattern 2019-07-29 23:09:22 +03:00
mvc remove some examples learning content as they are exist on the wiki itself now 2019-07-23 17:47:28 +03:00
orm add the gorm example from: https://github.com/kataras/iris/pull/1275 2019-07-23 18:18:36 +03:00
overview Version 11 released. Read https://github.com/kataras/iris/blob/master/HISTORY.md#su-21-october-2018--v1100 2018-10-21 19:20:05 +03:00
routing add a test near to the _examples/routing/basic example 2019-07-30 06:04:08 +03:00
sessions minor version 11.2.2 - register sessions as middleware and Context.HTML/Text like Context.Writef 2019-07-24 19:51:42 +03:00
structuring all examples and tests ran successfully based on iris v11.2.0 and go+gomodules 1.12.7 2019-07-17 01:56:41 +03:00
subdomains create the new FileServer and HandleDir, deprecate the rest APIBuilder/Party static methods and more 2019-06-21 19:43:25 +03:00
testing/httptest 8.4.0 | New MVC Features | Refactor examples and godoc for go 1.9 use. Read HISTORY.md. 2017-08-27 20:35:23 +03:00
tutorial all examples and tests ran successfully based on iris v11.2.0 and go+gomodules 1.12.7 2019-07-17 01:56:41 +03:00
versioning remove some examples learning content as they are exist on the wiki itself now 2019-07-23 17:47:28 +03:00
view resolve conflicts with current master v11.1.1 2019-07-23 19:20:07 +03:00
webassembly/basic create the new FileServer and HandleDir, deprecate the rest APIBuilder/Party static methods and more 2019-06-21 19:43:25 +03:00
websocket touches before release 2019-07-22 04:32:54 +03:00
README_ZH.md minor version 11.2.2 - register sessions as middleware and Context.HTML/Text like Context.Writef 2019-07-24 19:51:42 +03:00
README.md minor version 11.2.2 - register sessions as middleware and Context.HTML/Text like Context.Writef 2019-07-24 19:51:42 +03:00

Examples

Please do learn how net/http std package works, first.

This folder provides easy to understand code snippets on how to get started with iris micro web framework.

It doesn't always contain the "best ways" but it does cover each important feature that will make you so excited to GO with iris!

Running the examples

  1. Install the Go Programming Language, version 1.9+ from here.
  2. Install Iris: go get -u github.com/kataras/iris
  3. Install any external packages that required by the examples
External packages
cd _examples && go get ./...

And execute

$ cd $GOPATH/src/github.com/kataras/iris/_examples/overview
$ go run main.go

Test the examples by opening a terminal window and execute: GOCACHE=off && cd _examples && go test -v ./...

Overview

Structuring

Nothing stops you from using your favorite folder structure. Iris is a low level web framework, it has got MVC first-class support but it doesn't limit your folder structure, this is your choice.

Structuring depends on your own needs. We can't tell you how to design your own application for sure but you're free to take a closer look to the examples below; you may find something useful that you can borrow for your app;

HTTP Listening

Configuration

Routing, Grouping, Dynamic Path Parameters, "Macros" and Custom Context

  • app.Get("{userid:int min(1)}", myHandler)
  • app.Post("{asset:path}", myHandler)
  • app.Put("{custom:string regexp([a-z]+)}", myHandler)

Note: unlike other routers you'd seen, iris' router can handle things like these:

// Matches all GET requests prefixed with "/assets/"
app.Get("/assets/{asset:path}", assetsWildcardHandler)

// Matches only GET "/"
app.Get("/", indexHandler)
// Matches only GET "/about"
app.Get("/about", aboutHandler)

// Matches all GET requests prefixed with "/profile/"
// and followed by a single path part
app.Get("/profile/{username:string}", userHandler)
// Matches only GET "/profile/me" because 
// it does not conflict with /profile/{username:string}
// or the root wildcard {root:path}
app.Get("/profile/me", userHandler)

// Matches all GET requests prefixed with /users/
// and followed by a number which should be equal or bigger than 1
app.Get("/user/{userid:int min(1)}", getUserHandler)
// Matches all requests DELETE prefixed with /users/
// and following by a number which should be equal or bigger than 1
app.Delete("/user/{userid:int min(1)}", deleteUserHandler)

// Matches all GET requests except "/", "/about", anything starts with "/assets/" etc...
// because it does not conflict with the rest of the routes.
app.Get("{root:path}", rootWildcardHandler)

Navigate through examples for a better understanding.

Versioning

Dependency Injection

MVC

Subdomains

Convert http.Handler/HandlerFunc

View

You can serve quicktemplate and hero templates files too, simply by using the context#ResponseWriter, take a look at the http_responsewriter/quicktemplate and http_responsewriter/herotemplate examples.

Authentication

File Server

How to Read from context.Request() *http.Request

The context.Request() returns the same *http.Request you already know, these examples show some places where the Context uses this object. Besides that you can use it as you did before iris.

How to Write to context.ResponseWriter() http.ResponseWriter

The context/context#ResponseWriter() returns an enchament version of a http.ResponseWriter, these examples show some places where the Context uses this object. Besides that you can use it as you did before iris.

ORM

Miscellaneous

Experimental Handlers

More

https://github.com/kataras/iris/tree/master/middleware#third-party-handlers

Automated API Documentation

Testing

The httptest package is your way for end-to-end HTTP testing, it uses the httpexpect library created by our friend, gavv.

Example

Caching

iris cache library lives on its own package.

You're free to use your own favourite caching package if you'd like so.

Cookies

Sessions

iris session manager lives on its own package.

You're free to use your own favourite sessions package if you'd like so.

Websockets

Typescript Automation Tools

typescript automation tools have their own repository: https://github.com/kataras/iris/tree/master/typescript it contains examples

I'd like to tell you that you can use your favourite but I don't think you will find such a thing anywhere else.

Hey, You

Developers should read the godocs and https://docs.iris-go.com for a better understanding.

Psst, I almost forgot; do not forget to star or watch the project in order to stay updated with the latest tech trends, it never takes more than a second!