Skip to content

Instantly share code, notes, and snippets.

@AWeirdDev
Last active March 20, 2023 10:58
Show Gist options
  • Select an option

  • Save AWeirdDev/a32bfb1990ef6c0b819d7b156149a241 to your computer and use it in GitHub Desktop.

Select an option

Save AWeirdDev/a32bfb1990ef6c0b819d7b156149a241 to your computer and use it in GitHub Desktop.
rapiz-dl
from rapiz.app import API, APIContext
import time
api = API()
@api('/api/user', methods=['GET', 'POST'])
def user(res: APIContext):
return {
"name": "John Cena",
"timestamp": str(time.time())
}
EXPORT = api # !important
"""
Run this file to start the server.
Nothing else required.
"""
from rapiz.core import Rapiz
server = Rapiz()
server.start()
from rapiz.app import Middleware, MiddlewareContext
mdw = Middleware()
@mdw("*") # or "all"
def index(res: MiddlewareContext):
print("Wow, a new visitor!")
EXPORT = mdw # !important
# route: /
from rapiz.app import Writer
writer = Writer()
html = writer.html
markdown = writer.markdown
writer.write(
(
markdown("# Welcome to my website!"),
html("button", onClick="times += 1") << "Click me!",
html("p") << "You clicked %times% times!"
)
)
EXPORT = writer # !important
{
"version": "beta",
"goodLuck": true,
"backend": {
"host": "0.0.0.0",
"port": 8080,
"entrypoint": "main.py",
"manuallySetStaticFiles": false,
"startUpScripts": [
"echo Starting..."
]
},
"frontend": {
"pages": "pages",
"middleware": "middleware.py",
"api": "api"
},
"commands": {
"new": false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment