Skip to content

Commit 7c35ba7

Browse files
Merge pull request #45 from CreatCodeBuild/dev
Dev
2 parents 6054f4a + 8d8da43 commit 7c35ba7

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

docs/tutorials.rst

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ Chapter 2: Static File Server
6161
=============================
6262
Although you might want your App to be as dynamic as possible, you have to first understand how a static website is served.
6363

64+
The convention is to have a :code:`public` directory under your project directory and have all your static files there.
65+
66+
For example, if the client does :code:`GET /some_file.format`, the framework will try to read the path :code:`public/some_file.format` and sent what it read to the client. If the path does not exist, then the framework simply reports resource not found.
67+
68+
Therefore, you can easily just put all your frontend code under the public directory and start serving your application.
69+
6470
Chapter 3: REST
6571
===============
6672
Web is built on HTTP and HTTP is all about semantics. While there are thousands of ways to build HTTP API, the one which our framework embraces is REST. Since our audience's experience varies, I do not want to confuse you by explaining too much about REST. The only thing you need to know is that HTTP requests are all about semantics and a REST API is a semantic API.
@@ -73,13 +79,22 @@ First, let's see the frontend code:
7379
7480
fetch('/top10', {method: 'GET'});
7581
76-
:code:`fetch()` is the new browser API which does async HTTP requests. It is better than :code:`XMLHttpRequest` in almost every aspects. It has a cleaner interface which super fits REST.
82+
:code:`fetch()` is the new browser API which does async HTTP requests. It is better than :code:`XMLHttpRequest` in almost every aspects. It has a cleaner interface which fits RESTful API design.
7783

7884
This line creates a HTTP GET request with :code:`:path` = :code:`/top10`. How to respond to this request is 100% up to the server. Now, in :code:`app.py`, write this piece of code:
7985

8086
.. code-block:: Python
8187
82-
To be continued...
88+
# define API's callback function
89+
async def top10_api(request, response):
90+
await response.send("some data")
91+
92+
# register this function
93+
app.get("top10", top10_api)
94+
# you can also do
95+
# app.get("/top10", top10_api)
96+
97+
Now, whenever the client does such a request, :code:`top10_api` will be run by the framework. We call this function the endpoint of a REST API. You can define the function as whatever you need, but have to include the :code:`async` and :code:`await` key words.
8398

8499
Chapter 4: Parameterized REST
85100
=============================

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
from setuptools import setup
55

6-
from hyper2web import __version__
7-
86
with open('README.rst') as readme_file:
97
readme = readme_file.read()
108

@@ -23,7 +21,7 @@
2321

2422
setup(
2523
name='hyper2web',
26-
version=__version__,
24+
version='0.0.3',
2725
description="Coroutine based H2 Web backend framework built for the future.",
2826
long_description=readme + '\n\n' + history,
2927
author="Xuanzhe Wang",

0 commit comments

Comments
 (0)