This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from browser import alert, document, ajax, html | |
base_url = "http://127.0.0.1:8000/" | |
def click_get_all_books(event): | |
get_all_books() | |
def get_all_books(): | |
url = base_url + "books" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="utf-8"> | |
<link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre.min.css"> | |
<link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre-exp.min.css"> | |
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/brython.min.js"></script> | |
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/brython_stdlib.js"></script> | |
</head> | |
<body onload="brython()"> | |
<div class="container"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
from dataclasses import dataclass | |
from contextlib import asynccontextmanager | |
from litestar.exceptions import HTTPException | |
from litestar import Litestar, get, post, put, patch, delete | |
from litestar.dto import AbstractDTO, field, DataclassDTO, DTOConfig, DTOData | |
from litestar.contrib.sqlalchemy.dto import SQLAlchemyDTO | |
from sqlalchemy.orm import Mapped, mapped_column | |
from sqlalchemy import Column, Integer, String, create_engine | |
from sqlalchemy.ext.declarative import declarative_base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import logging | |
logging.getLogger('faker').setLevel(logging.ERROR) | |
HOST = "http://127.0.0.1" | |
PORT = "8000" | |
BASE_URL = HOST + ":" + PORT | |
def test_list_users(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
from litestar import Litestar, get, post, delete | |
from litestar.exceptions import HTTPException | |
@dataclass | |
class User(): | |
user_id: int | |
name: str | |
age: int | |
email: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
from dataclasses import dataclass | |
from litestar import Litestar, post, get, patch, put | |
from litestar.dto import DataclassDTO, DTOConfig, DTOData | |
from litestar.exceptions import HTTPException | |
@dataclass | |
class Book: | |
title: str | |
author: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>User listing</title> | |
<style> | |
table { | |
font-family: arial, sans-serif; | |
border-collapse: collapse; | |
width: 100%; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>My Webpage</title> | |
</head> | |
<body> | |
<h1>Hello user: {{ name }}!</h1> | |
{# a comment #} | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from litestar import Litestar, get | |
from litestar.contrib.jinja import JinjaTemplateEngine | |
from litestar.response import Template | |
from litestar.template.config import TemplateConfig | |
from litestar.exceptions import HTTPException | |
from pydantic import BaseModel | |
class User(BaseModel): | |
user_id: int | |
name: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from asyncio import sleep | |
from typing import Any | |
from litestar import Litestar, get | |
@get("/async") | |
async def async_hello_world() -> dict[str, Any]: | |
await sleep(0.1) | |
return {"hello": "world"} | |
@get("/sync", sync_to_thread=False) |
NewerOlder