How to write a web framework

25
How to write a web framework With illustration using Sinetja and Xitrum Ngoc Dao Sunday Oct 26 2014

description

In this talk I'd like to share experience about writing web frameworks

Transcript of How to write a web framework

How to writea web frameworkWith illustration using Sinetja and Xitrum

Ngoc DaoSunday Oct 26 2014

About this presentation

• I want to share some experience about writing web frameworks.

About Ngoc• Came to Japan to study and work in 2001

• Studied electrical engineering at Takamatsu 高専 andcomputer vision at Tsukuba 大学

• Worked at several software startups:Murakumo (Kokolink), GNT, KAYAC, Mobilus

• Interests: web frameworks, distributed systems, realtime systems

• Have been writing some web frameworks since 20092 in Erlang, 1 in Scala, 1 in Java

• Open source:https://github.com/ngocdaothanh

Discussion question

• Have you ever written a web app?

• What are your favorite web frameworks?

• My favorite: Ruby on Rails

• It's a beautifulopinionatedconvention over configurationweb framework

https://gettingreal.37signals.com/ch04_Make_Opinionated_Software.php

Some people argue software should be agnostic. They say it's arrogant for developers to limit features or ignore feature requests. They say software should always be as flexible as possible.

We think that's bullshit. The best software has a vision. The best software takes sides. When someone uses software, they're not just looking for features, they're looking for an approach. They're looking for a vision. Decide what your vision is and run with it.

And remember, if they don't like your vision there are plenty of other visions out there for people. Don't go chasing people you'll never make happy.

Discussion question

• What are the differences betweenlibrary and framework?

• In my opinion

Library is about features

Framework is about workflow and connecting other existing libraries

Discussion question

• How hard to write a web framework?

• In my opinion,

Writing a framework is 10x harder than writing a library,

Because:- You need to know how to use and connect many libraries- You need to have much experience to have your vision, to make your framework opinionated

• Writing a library ~ Playing a music instrumentWriting a framework ~ Conducting an orchestra

• Vision example:

Xitrum:- Easy async- Easy cluster- Beautiful API

Discussion question

• How market your web framework?How to let users know about and use it?How to create a community around it?

Discussion question

• What happens behind the scene

from the time when you type URL in the browser address bar and press ENTER

to the time the web page is displayed?

(Note: This is a Google interview question)

Discussion question

• What are the differences betweena command line program anda web program?

• What are the similarities between them?

Discussion question

• What are the features that you think a web framework should have? What are the things that you think a web framework should do for you?

• What is the most important part in a web framework?

• In my opinion,

the most important part in a web framework is the router.

• Use curl and telnet to demo

Structure ofHTTP request and response

• Request method + path info-> Router-> Which action to dispatch the request to

Routefrom request

to action

• Stacked handlers:

Request-> Handler 1-> Handler 2-> …-> Response

• Handler examples: router, dispatcher, static file server, response cacher etc.

Structure ofrequest processing pipeline

• Sinetjahttps://github.com/sinetja/sinetja

• Xitrumhttp://xitrum-framework.github.io/

(Show how beautiful the APIs look like :D)

Demo