• No results found

Nifty web apps on an OpenResty

N/A
N/A
Protected

Academic year: 2021

Share "Nifty web apps on an OpenResty"

Copied!
53
0
0

Loading.... (view fulltext now)

Full text

(1)
(2)

Nifty

web apps on an

OpenResty

[email protected]

章亦春

(3)
(4)

The

history

of the

web

...

(5)
(6)

Benefits

☺ Server code is easy to write.

☺ Browsers are easty to build as well. ☺ Web 1.0 Spiders are happy.

Drawbacks

☺ Pages refresh everytime the user takes an action. ☺ Advanced spiders try very hard to extract data

from HTML source.

(7)

The

history

of the

web

...

Web 1.0

(8)
(9)

Benefits

☺ Data can be applied to view templates on client side.

☺ Pages can be highly responsive via updaing just page regions.

Drawbacks

☹ Server of the site owner is very fat,

(10)

The

history

of the

web

...

Web 1.0

Web 2.0

(11)
(12)

Benefits

No database required on the site owner's server

☺ Database has the full posibility to scale

Drawbacks

Two HTTP round-trips are required

(13)

The

history

of the

web

...

Web 1.0

Web 2.0

Post-mordern Web 2.0

Web X

(14)
(15)

Benefits

☺ Clients access third-party service sites directly. ☺ Service is general, composible,

and even recursive.

☺ All the Web 2.0 goodies.

☺ Site owner's server is extremely thin. Deployment of web sites is trivial.

Drawbacks (which may be benefits at the same time) ☹ Web 1.0 spiders cannot find anything interesting at all in the HTML.

☹ Web sites are too easy to steal and re-distributed by others

(16)

We have

already

produced such web sites

belonging to the

Web X

era!

They're

powered

by the

OpenResty

platform.

They're written

completely

in

JavaScript

.

(17)

My

blog

site

(18)
(19)

Yisou

BBS

(20)
(21)

OpenResty

Admin

site

(22)
(23)
(24)

My blog site

=

index.html

+

openresty.js

+

blog.js

+

jemplates.js

+

jquery.js

+

JSON.js

+

CSS/image

(25)
(26)

Hey, my

readers

can write a

new

blog

site for my articles atop

the

OpenResty

API

exposed by my "

agentzh

" account

(27)

<!-- index.html -->

<html>

<head>

<meta http-equiv="Content-Type"

content="text/html; charset=

utf-8

" />

<script src="

JSON.js

"></script>

<script src="

openresty.js

"></script>

<script src="

blog.js

"></script>

<title>My blog</title>

</head>

<body onload="

init()

">

<div id="

main

"></div>

</body>

(28)

// blog.js

var openresty = null;

function init () {

openresty = new OpenResty.Client( { server: 'http://api.eeeeworks.org', user: 'agentzh.Public' } ); openresty.callback = renderPosts; openresty.get( '/=/model/Post/~/~',

{ offset: 0, count: 10, order_by: 'id:desc' } );

(29)

// blog.js (continued)

function renderPosts (res) { if (openresty.isSuccess(res)) { var html = '';

for (var i = 0; i < res.length; i++) { var post = res[i];

html += "<h1>" + post.title + "</h1>" + post.content + "<p>Posted by " + post.author + "</p>"; } document.getElementById("main").innerHTML = html; } else {

alert("Failed to fetch posts: " + res.error); }

(30)
(31)

Hey, it

runs

now!

(32)
(33)
(34)

Concatenating

HTML strings is

boring

and no fun :(

(35)

<!-- post-list.tt -->

[% FOREACH post = posts %]

<h1>

[% post.title %]

</h1>

[% post.content %]

<p>Posted by

[% post.author %]

</p>

(36)

$

jemplate

--runtime > jemplates.js

(37)

<!-- index.html --> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="JSON.js"></script> <script src="openresty.js"></script> <script src="blog.js"></script> <script src="jemplates.js"></script> <title>My blog</title> </head> <body onload="init()"> <div id="main"></div> </body> </html>

(38)

// blog.js (continued)

function renderPosts (res) { if (openresty.isSuccess(res)) { var html = Jemplate.process( 'post-list.tt', { posts: res } );

document.getElementById("main").innerHTML = html; } else {

alert("Failed to fetch posts: " + res.error); }

(39)
(40)

Hey, it

runs

again!

(41)
(42)

OpenResty is a

general-purpose RESTful web service platform REST wrapper for relational databases

Virtual web runtime for RIA

"meta web site" supporting other sites via web services

handy web database which can be accessed from anywhere

(43)

OpenResty

is

NOT

a

×

server

-side web application

framework

.

×

relacement for highly scalable

semi-structured

data storage solutions

like Amazon SimpleDB or CouchDB.

(44)

OpenResty

offers

(scalable)

relational

data

storage

truely

RESTy

interface

JSON/YAML

data transfer format

SQL

-based reusable

views

a REST-oriented

role system

for

ACL

view

-based

RSS feeds

user-defined

actions

in

RestyScript

native

captchas

(45)

The OpenResty

FastCGI

server

is currently written in

Perl 5

.

(46)
(47)

The

PgFarm

backend of OpenResty

is designed to be

scalable

.

(48)
(49)

"

How

can I get

started

?"

Write to

[email protected]

to request

an OpenResty

account

OpenResty is on

CPAN

already!

(50)

"Where can I learn more about OpenResty?"

➥ See the OpenResty::Spec::Overview document

(51)

"How can I get involved?"

➥ Write to [email protected] to ask a commit bit! http://svn.openfoundry.org/openapi/trunk

(52)
(53)

References

Related documents

Lone pair on oxygen comes down to form carbonyl, enol double bond displaces leaving group on the β-carbon.. Backside attack of nucleophile onto electrophile alkyl halide

[r]

Perceptions of recognition and appreciation of the function of the OSH practitioner, and the existence of a broadly shared culture of health and safety at work, has a positive

One burrito filled with Spanish rice, pinto beans, shredded cheese, chile con queso and your choice of shredded chicken, ground beef, chicken fajita or beef fajita.. Served

The amount shown for the subject property is sold data where available, or the property's estimated value when sales data are unavailable (such as a non-disclosure state) or provided

Companies buy email archiving systems to reduce the cost of email storage, to comply with regulations and to give staff better access to business information stored in email

Another device, a Section 2503(c) trust (named after the relevant Internal Revenue Code section), or minor’s exclusion trust, allows a donor to make gifts to a minor in