iris/_examples
Gerasimos (Makis) Maropoulos dbd6fcd2d7 add Context.SendFileWithRate, ServeFileWithRate and ServeContentWithRate
as requested at: https://github.com/kataras/iris/issues/1493


Former-commit-id: 7783fde04b4247056e6309e7ec1df27f027dc655
2020-05-02 17:46:17 +03:00
..
apidoc/yaag don't fire ErrServerClosed on manually interrupt signals (CTRL/CMD+C) 2020-04-28 05:22:58 +03:00
authentication examples: replace all app.Run(iris.Addr(...)) with app.Listen just for the shake of simplicity, both are doing the same exact thing as it's described on the http listening first example. 2020-03-05 22:41:27 +02:00
cache examples: replace all app.Run(iris.Addr(...)) with app.Listen just for the shake of simplicity, both are doing the same exact thing as it's described on the http listening first example. 2020-03-05 22:41:27 +02:00
configuration improve remote addr parsing as requested at: https://github.com/kataras/iris/issues/1453 2020-04-20 10:43:45 +03:00
convert-handlers examples: replace all app.Run(iris.Addr(...)) with app.Listen just for the shake of simplicity, both are doing the same exact thing as it's described on the http listening first example. 2020-03-05 22:41:27 +02:00
cookies examples: replace all app.Run(iris.Addr(...)) with app.Listen just for the shake of simplicity, both are doing the same exact thing as it's described on the http listening first example. 2020-03-05 22:41:27 +02:00
dependency-injection/basic more route info improvements 2020-04-28 22:34:36 +03:00
desktop-app new 'Party.DI()' method to return the Party's instance of the new 'APIBuilderDI' and move the DI-relative Router to this new APIBuilderDI 2020-04-08 20:04:56 +03:00
docker fix .dokerignore to .dockerignore 2020-03-19 16:13:47 +08:00
experimental-handlers examples: replace all app.Run(iris.Addr(...)) with app.Listen just for the shake of simplicity, both are doing the same exact thing as it's described on the http listening first example. 2020-03-05 22:41:27 +02:00
file-server add Context.SendFileWithRate, ServeFileWithRate and ServeContentWithRate 2020-05-02 17:46:17 +03:00
hello-world don't fire ErrServerClosed on manually interrupt signals (CTRL/CMD+C) 2020-04-28 05:22:58 +03:00
hero don't fire ErrServerClosed on manually interrupt signals (CTRL/CMD+C) 2020-04-28 05:22:58 +03:00
http_request don't fire ErrServerClosed on manually interrupt signals (CTRL/CMD+C) 2020-04-28 05:22:58 +03:00
http_responsewriter add Context.SendFileWithRate, ServeFileWithRate and ServeContentWithRate 2020-05-02 17:46:17 +03:00
http-listening don't fire ErrServerClosed on manually interrupt signals (CTRL/CMD+C) 2020-04-28 05:22:58 +03:00
i18n examples: replace all app.Run(iris.Addr(...)) with app.Listen just for the shake of simplicity, both are doing the same exact thing as it's described on the http listening first example. 2020-03-05 22:41:27 +02:00
miscellaneous minor (see prev commit) 2020-05-01 23:37:41 +03:00
mvc more route info improvements 2020-04-28 22:34:36 +03:00
orm add human-friendly middleware names on route debugging (see HISTORY.md#Next) 2020-04-28 05:42:23 +03:00
overview add context.Protobuf, MsgPack, ReadProtobuf, ReadMsgPack methods 2020-04-08 16:48:22 +03:00
routing minor 2020-04-29 05:50:29 +03:00
sessions don't fire ErrServerClosed on manually interrupt signals (CTRL/CMD+C) 2020-04-28 05:22:58 +03:00
sitemap examples: replace all app.Run(iris.Addr(...)) with app.Listen just for the shake of simplicity, both are doing the same exact thing as it's described on the http listening first example. 2020-03-05 22:41:27 +02:00
structuring examples: replace all app.Run(iris.Addr(...)) with app.Listen just for the shake of simplicity, both are doing the same exact thing as it's described on the http listening first example. 2020-03-05 22:41:27 +02:00
subdomains examples: replace all app.Run(iris.Addr(...)) with app.Listen just for the shake of simplicity, both are doing the same exact thing as it's described on the http listening first example. 2020-03-05 22:41:27 +02:00
testing/httptest examples: replace all app.Run(iris.Addr(...)) with app.Listen just for the shake of simplicity, both are doing the same exact thing as it's described on the http listening first example. 2020-03-05 22:41:27 +02:00
tutorial update dependencies 2020-04-28 05:51:28 +03:00
versioning examples: replace all app.Run(iris.Addr(...)) with app.Listen just for the shake of simplicity, both are doing the same exact thing as it's described on the http listening first example. 2020-03-05 22:41:27 +02:00
view add context.Protobuf, MsgPack, ReadProtobuf, ReadMsgPack methods 2020-04-08 16:48:22 +03:00
webassembly/basic examples: replace all app.Run(iris.Addr(...)) with app.Listen just for the shake of simplicity, both are doing the same exact thing as it's described on the http listening first example. 2020-03-05 22:41:27 +02:00
websocket add human-friendly middleware names on route debugging (see HISTORY.md#Next) 2020-04-28 05:42:23 +03:00
README_ZH.md remove the 'typescript' package entirely in favor of iris-cli and because the alm editor was deprecated by its author (consider using the designtsx.com instead) 2020-04-19 16:47:15 +03:00
README.md add Context.SendFileWithRate, ServeFileWithRate and ServeContentWithRate 2020-05-02 17:46:17 +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 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.12+ from https://golang.org/dl.
  2. Install Iris
  3. Install any external packages that required by the examples
External packages
cd _examples && go get ./...

And run each example you wanna see, e.g.

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

Test the examples by opening a terminal window and execute: 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.

Localization and Internationalization

Sitemap

Desktop App

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

Community-based 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

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!