diff --git a/tutorials/building-a-simple-web-blog-with-vweb.md b/tutorials/building-a-simple-web-blog-with-vweb.md
index 58431fd3c3..ffbb2a224c 100644
--- a/tutorials/building-a-simple-web-blog-with-vweb.md
+++ b/tutorials/building-a-simple-web-blog-with-vweb.md
@@ -317,6 +317,69 @@ article := app.retrieve_article(10) or {
> `db := app.db` is a temporary limitation in the
V ORM, soon this will not be needed.
+
+### Adding new articles
+
+Create `new.html`:
+
+```html
+
+
+
+
+
+
+```
+
+```v
+pub fn (app mut App) new_article() {
+ title := app.vweb.form['title']
+ text := app.vweb.form['text']
+ if title == '' || text == '' {
+ app.vweb.text('Empty text/titile')
+ return
+ }
+ article := Article{
+ title: title
+ text: text
+ }
+ db := app.db
+ db.insert(article)
+ app.vweb.redirect('/article/')
+}
+```
+
+> Untyped `form['key']` is temporary. Very soon Vweb will accept query and form
+parameters via function arguments: `new_article(title, text string) {`.
+
+We need to update `index.html` to add a link to the "new article" page:
+New article
+
+
+
+### JSON endpoints
+
+This tutorial used the traditional server side rendering. If you prefer
+to render everything on the client or need an API, creating JSON endpoints
+in V is very simple:
+
+```v
+pub fn (app mut App) articles() {
+ articles := app.find_all_articles()
+ app.vweb.json(json.encode(articles))
+}
+```
+
+
+
+
+
To be continued on Dec 14...
For an example of a more sophisticated web app written in V, check out Vorum: https://github.com/vlang/vorum
diff --git a/tutorials/code/blog/blog.v b/tutorials/code/blog/blog.v
index 6e0c505524..d6c70d63fd 100644
--- a/tutorials/code/blog/blog.v
+++ b/tutorials/code/blog/blog.v
@@ -4,6 +4,7 @@ import (
vweb
time
pg
+ json
)
struct App {
@@ -42,6 +43,32 @@ pub fn (app mut App) init() {
app.db = db
}
+pub fn (app mut App) new() {
+ $vweb.html()
+}
+
+pub fn (app mut App) new_article() {
+ title := app.vweb.form['title']
+ text := app.vweb.form['text']
+ if title == '' || text == '' {
+ app.vweb.text('Empty text/titile')
+ return
+ }
+ article := Article{
+ title: title
+ text: text
+ }
+ println(article)
+ db := app.db
+ db.insert(article)
+ app.vweb.redirect('/article/')
+}
+
+pub fn (app mut App) articles() {
+ articles := app.find_all_articles()
+ app.vweb.json(json.encode(articles))
+}
+
fn (app mut App) time() {
app.vweb.text(time.now().format())
}
diff --git a/tutorials/code/blog/index.html b/tutorials/code/blog/index.html
index 4ec36c56a6..b2541c94f6 100644
--- a/tutorials/code/blog/index.html
+++ b/tutorials/code/blog/index.html
@@ -9,6 +9,8 @@
@article.text
@end
+
+ New article