Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
# Project files
uWeb/*
!uWeb/404.html
Expand All @@ -6,7 +7,7 @@ uWeb/*
!uWeb/layout.html
!uWeb/uWeb.py
!uWeb/uWeb_uasyncio.py

main.py
### VisualStudioCode ###
.vscode/

Expand Down
Empty file modified LICENSE
100644 → 100755
Empty file.
128 changes: 70 additions & 58 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
- [μWeb vs. μWeb-uasyncio](#%ce%bcweb-vs-%ce%bcweb-uasyncio)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Example application using μWeb](#example-application-using-%ce%bcweb)
- [Example application using μWeb-uasyncio](#example-application-using-%ce%bcweb-uasyncio)
- [Example application using μWeb](#example-application-using-%ce%bcweb)
- [Example application using μWeb-uasyncio](#example-application-using-%ce%bcweb-uasyncio)
- [Using uWeb-uasyncio](#using-uweb-uasyncio)
- [Template Rendering](#template-rendering)
- [Layout Rendering](#layout-rendering)
Expand Down Expand Up @@ -96,88 +96,100 @@ You can run uWeb with the MicroPython unix port
```python
from uWeb import uWeb, loadJSON

server = uWeb("0.0.0.0", 8000) #init uWeb object
server = uWeb("0.0.0.0", 8000) # init uWeb object

def home(): #render HTML page
vars = {
'name': 'MicroPython',
'answer': (1+1)
}
server.render('content.html', variables=vars)

def header(): #send headers to client
def home(): # render HTML page
vars = {"name": "MicroPython", "answer": (1 + 1)}
server.render("content.html", variables=vars)


def header(): # send headers to client
server.sendStatus(server.OK)
server.sendHeaders({
'header1': 'one',
'header2': 'two',
'header3': 'three',
})
server.sendHeaders(
{"header1": "one", "header2": "two", "header3": "three",}
)


def post(): #print JSON body from client
def post(): # print JSON body from client
print(loadJSON(server.request_body).items())
server.sendStatus(server.OK)


def jsonn(): #send JSON to client
server.sendJSON({'status':'okkk'})
def jsonn(): # send JSON to client
server.sendJSON({"status": "okkk"})

#configure routes
server.routes(({
(uWeb.GET, "/"): home,
(uWeb.POST, "/post"): post,
(uWeb.GET, "/json"): jsonn,
(uWeb.GET, "/header"): header
}))
# configure routes
server.routes(
(
{
(uWeb.GET, "/"): home,
(uWeb.POST, "/post"): post,
(uWeb.GET, "/json"): jsonn,
(uWeb.GET, "/header"): header,
}
)
)

#start server
# start server
server.start()

```

### Example application using μWeb-uasyncio

```python
import uasyncio

from uWeb_uasyncio import uWeb_uasyncio as uWeb
from uWeb_uasyncio import loadJSON

server = uWeb("0.0.0.0", 8000) #init uWeb object
server = uWeb("0.0.0.0", 8000) # init uWeb object


def home(): #render HTML page
vars = {
'name': 'MicroPython',
'answer': (1+1)
}
await server.render('content.html', variables=vars)
def home(): # render HTML page
vars = {"name": "MicroPython", "answer": (1 + 1)}
await server.render("content.html", variables=vars)

def printTen(): # counts to ten while still accepting incoming requests

def printTen(): # counts to ten while still accepting incoming requests
await server.sendStatus(server.OK)
for i in range(10):
print(i)
await uasyncio.sleep(1)

def header(): #send headers to client

def header(): # send headers to client
await server.sendStatus(server.OK)
await server.sendHeaders({
'header1': 'one',
'header2': 'two',
'header3': 'three',
})

def post(): #print JSON body from client
print('Payload: ', loadJSON(server.request_body))
await uasyncio.sleep(0)

def jsonn(): #send JSON to client
await server.sendJSON({'status':'okkk'})

#configure routes
server.routes(({
(uWeb.GET, "/"): home,
(uWeb.GET, "/ten"): printTen,
(uWeb.POST, "/post"): post,
(uWeb.GET, "/json"): jsonn,
(uWeb.GET, "/header"): header
}))

#start server
await server.sendHeaders(
{"header1": "one", "header2": "two", "header3": "three",}
)


def post(): # print JSON body from client
print("Payload: ", loadJSON(server.request_body))
await server.sendStatus(server.OK)



def jsonn(): # send JSON to client
await server.sendJSON({"status": "okkk"})


# configure routes
server.routes(
(
{
(uWeb.GET, "/"): home,
(uWeb.GET, "/ten"): printTen,
(uWeb.POST, "/post"): post,
(uWeb.GET, "/json"): jsonn,
(uWeb.GET, "/header"): header,
}
)
)

# start server
server.start()
```

Expand Down
Empty file modified _config.yml
100644 → 100755
Empty file.
Binary file modified bin/micropython
Binary file not shown.
Empty file modified docs/uWeb-uasyncio.md
100644 → 100755
Empty file.
Empty file modified docs/uWeb.md
100644 → 100755
Empty file.
Empty file modified example/content.html
100644 → 100755
Empty file.
Empty file modified example/layout.html
100644 → 100755
Empty file.
Empty file modified example/random.js
100644 → 100755
Empty file.
55 changes: 30 additions & 25 deletions example/uWeb_example.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
import sys
sys.path.append('../uWeb')

sys.path.append("../uWeb") # remove this when deploying to a board
from uWeb import uWeb, loadJSON

server = uWeb("0.0.0.0", 8000) #init uWeb object
server = uWeb("0.0.0.0", 8000) # init uWeb object


def home(): # render HTML page
vars = {"name": "MicroPython", "answer": (1 + 1)}
server.render("content.html", variables=vars)

def home(): #render HTML page
vars = {
'name': 'MicroPython',
'answer': (1+1)
}
server.render('content.html', variables=vars)

def header(): #send headers to client
def header(): # send headers to client
server.sendStatus(server.OK)
server.sendHeaders({
'header1': 'one',
'header2': 'two',
'header3': 'three',
})
server.sendHeaders(
{"header1": "one", "header2": "two", "header3": "three",}
)

def post(): #print JSON body from client

def post(): # print JSON body from client
print(loadJSON(server.request_body).items())
server.sendStatus(server.OK)


def jsonn(): #send JSON to client
server.sendJSON({'status':'okkk'})
def jsonn(): # send JSON to client
server.sendJSON({"status": "okkk"})

#configure routes
server.routes(({
(uWeb.GET, "/"): home,
(uWeb.POST, "/post"): post,
(uWeb.GET, "/json"): jsonn,
(uWeb.GET, "/header"): header
}))
# configure routes
server.routes(
(
{
(uWeb.GET, "/"): home,
(uWeb.POST, "/post"): post,
(uWeb.GET, "/json"): jsonn,
(uWeb.GET, "/header"): header,
}
)
)

#start server
# start server
server.start()
73 changes: 40 additions & 33 deletions example/uWeb_uasyncio_example.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
import sys
import uasyncio
sys.path.append('../uWeb') # remove this if deploying to a board

sys.path.append("../uWeb") # remove this if deploying to a board
from uWeb_uasyncio import uWeb_uasyncio as uWeb
from uWeb_uasyncio import loadJSON

server = uWeb("0.0.0.0", 8000) #init uWeb object
server = uWeb("0.0.0.0", 8000) # init uWeb object


def home(): #render HTML page
vars = {
'name': 'MicroPython',
'answer': (1+1)
}
await server.render('content.html', variables=vars)
def home(): # render HTML page
vars = {"name": "MicroPython", "answer": (1 + 1)}
await server.render("content.html", variables=vars)

def printTen(): # counts to ten while still accepting incoming requests

def printTen(): # counts to ten while still accepting incoming requests
await server.sendStatus(server.OK)
for i in range(10):
print(i)
await uasyncio.sleep(1)

def header(): #send headers to client

def header(): # send headers to client
await server.sendStatus(server.OK)
await server.sendHeaders(
{"header1": "one", "header2": "two", "header3": "three",}
)


def post(): # print JSON body from client
print("Payload: ", loadJSON(server.request_body))
await server.sendStatus(server.OK)
await server.sendHeaders({
'header1': 'one',
'header2': 'two',
'header3': 'three',
})

def post(): #print JSON body from client
print('Payload: ', loadJSON(server.request_body))
await uasyncio.sleep(0)

def jsonn(): #send JSON to client
await server.sendJSON({'status':'okkk'})

#configure routes
server.routes(({
(uWeb.GET, "/"): home,
(uWeb.GET, "/ten"): printTen,
(uWeb.POST, "/post"): post,
(uWeb.GET, "/json"): jsonn,
(uWeb.GET, "/header"): header
}))

#start server



def jsonn(): # send JSON to client
await server.sendJSON({"status": "okkk"})


# configure routes
server.routes(
(
{
(uWeb.GET, "/"): home,
(uWeb.GET, "/ten"): printTen,
(uWeb.POST, "/post"): post,
(uWeb.GET, "/json"): jsonn,
(uWeb.GET, "/header"): header,
}
)
)

# start server
server.start()
Empty file modified uWeb/404.html
100644 → 100755
Empty file.
Empty file modified uWeb/500.html
100644 → 100755
Empty file.
Empty file modified uWeb/layout.html
100644 → 100755
Empty file.
Loading