diff --git a/README.md b/README.md
index 8f4785e8..f51eaa85 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ Thank you to all our backers! 🙏 [Become a backer](https://iris-go.com/donate)
```sh
-$ cat example.go
+$ cat _examples/cookies/basic/main.go
```
```go
@@ -27,57 +27,102 @@ package main
import "github.com/kataras/iris"
-func main() {
+func newApp() *iris.Application {
app := iris.New()
- // Load all templates from the "./views" folder
- // where extension is ".html" and parse them
- // using the standard `html/template` package.
- app.RegisterView(iris.HTML("./views", ".html"))
- // Method: GET
- // Resource: http://localhost:8080
- app.Get("/", func(ctx iris.Context) {
- // Bind: {{.message}} with "Hello world!"
- ctx.ViewData("message", "Hello world!")
- // Render template file: ./views/hello.html
- ctx.View("hello.html")
+ // Set A Cookie.
+ app.Get("/cookies/{name}/{value}", func(ctx iris.Context) {
+ name := ctx.Params().Get("name")
+ value := ctx.Params().Get("value")
+
+ ctx.SetCookieKV(name, value)
+
+ ctx.Writef("cookie added: %s = %s", name, value)
})
- // Method: GET
- // Resource: http://localhost:8080/user/42
- //
- // Need to use a custom regexp instead?
- // Easy,
- // just mark the parameter's type to 'string'
- // which accepts anything and make use of
- // its `regexp` macro function, i.e:
- // app.Get("/user/{id:string regexp(^[0-9]+$)}")
- app.Get("/user/{id:long}", func(ctx iris.Context) {
- userID, _ := ctx.Params().GetInt64("id")
- ctx.Writef("User ID: %d", userID)
+ // Retrieve A Cookie.
+ app.Get("/cookies/{name}", func(ctx iris.Context) {
+ name := ctx.Params().Get("name")
+
+ value := ctx.GetCookie(name)
+
+ ctx.WriteString(value)
})
- // Start the server using a network address.
+ // Delete A Cookie.
+ app.Delete("/cookies/{name}", func(ctx iris.Context) {
+ name := ctx.Params().Get("name")
+
+ ctx.RemoveCookie(name)
+
+ ctx.Writef("cookie %s removed", name)
+ })
+
+ return app
+}
+
+func main() {
+ app := newApp()
+
+ // GET: http://localhost:8080/cookies/my_name/my_value
+ // GET: http://localhost:8080/cookies/my_name
+ // DELETE: http://localhost:8080/cookies/my_name
app.Run(iris.Addr(":8080"))
}
```
-> Learn more about path parameter's types by clicking [here](_examples/routing/dynamic-path/main.go#L31)
+* Alternatively, use a regular `http.Cookie`: `ctx.SetCookie(&http.Cookie{...})`
+* If you want to set custom the path: `ctx.SetCookieKV(name, value, iris.CookiePath("/custom/path/cookie/will/be/stored"))`.
+* If you want to be available only to the current request path: `ctx.SetCookieKV(name, value, iris.CookieCleanPath /* or iris.CookiePath("") */)`
+ * `iris.CookieExpires(time.Duration)`
+ * `iris.CookieHTTPOnly(false)`
+* `ctx.Request().Cookie(name)` is also available, it's the `net/http` approach
+* Learn more about path parameter's types by clicking [here](_examples/routing/dynamic-path/main.go#L31).
-```html
-
-
-