【HttpRunner】学习准备

2023-05-16

1、安装python 3.7及以上版本:

2、安装fastapi:pip install fastapi[all]

3、把如下代码粘贴复制到main.py文件中:

from fastapi import FastAPI
from typing import Union
from pydantic import BaseModel
app = FastAPI()

class Item(BaseModel):
    name: str
    description: Union[str, None] = None
    price: float
    tax: Union[float, None] = None



@app.get("/")
async def root():
    return {"message": "Test HttpRunner Demo"}


@app.get("/items/{item_id}")
async def read_item(item_id: str, q: Union[str, None] = None, short: bool = False):
    item = {"item_id": item_id}
    if q:
        item.update({"q": q})
    if not short:
        item.update(
            {"description": "This is an amazing item that has a long description"}
        )
    return item


@app.get("/users/{user_id}/items/{item_id}")
async def read_user_item(
    user_id: int, item_id: str, q: Union[str, None] = None, short: bool = False
):
    item = {"item_id": item_id, "owner_id": user_id}
    if q:
        item.update({"q": q})
    if not short:
        item.update(
            {"description": "This is an amazing item that has a long description"}
        )
    return item


@app.post("/additems/")
async def create_item(item: Item):
    return item


@app.put("/items/{item_id}")
def update_item(item_id: int, item: Item):
    return {"item_name": item.name, "item_id": item_id}

4、进入main.py所在目录执行命令:uvicorn main:app --reload

5、访问界面:http://127.0.0.1:8000/docs

在这里插入图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【HttpRunner】学习准备 的相关文章

  • [leetcode]347. Top K Frequent Elements

    Given a non empty array of integers return the k most frequent elements Example 1 Input nums 61 1 1 1 2 2 3 k 61 2 Outpu
  • [leetcode]206. Reverse Linked List

    Reverse a singly linked list Example Input 1 gt 2 gt 3 gt 4 gt 5 gt NULL Output 5 gt 4 gt 3 gt 2 gt 1 gt NULL Follow up
  • [ERROR]ubuntu18.04自带中文输入法在输入中文选择内容的时候出现数字而不是中文

    ubuntu18 04自带中文输入法在输入中文选择内容的时候出现数字而不是中文 今天早上遇到了这个问题 xff0c sudo rm rf xff5e cache ibus libpinyin 重启电脑 解决
  • [leetcode]237. Delete Node in a Linked List

    Write a function to delete a node except the tail in a singly linked list given only access to that node Given linked li
  • [leetcode]78. Subsets

    Given a set of distinct integers nums return all possible subsets the power set Note The solution set must not contain d
  • 使用telnet发送email(内嵌图片,附件)

    使用telnet发送email 内嵌图片 xff0c 附件 因为最近想复习一下smtp协议所以无聊的本人想使用telnet发送email xff0c 虽然比较简单但还是记录下来希望可以给一些需要的朋友帮助吧 准备 xff1a 首先本人实在w
  • C/C++中 sizeof 详解

    摘要 xff1a Sizeof的作用非常简单 xff1a 求对象或者类型的大小 然而sizeof又非常复杂 xff0c 它涉及到很多特殊情况 xff0c 本篇把这些情况分门别类 xff0c 总结出了sizeof的10个特性 xff1a 0
  • Android中包含List成员变量的Parcel以及Parcel嵌套写法示例

    这个Scean类实现了Parcelable接口 xff0c 同时其内部的成员变量List lt SubScean gt subSceanList 中的SubScean类也实现了Parcelable接口 public class Scean
  • 第一节:详细透彻解读Git与SVN的区别(集中式VS分布式)

    Git是目前世界上最先进的分布式版本控制系统 xff0c 其实 Git 跟 SVN一样有自己的集中式版本库或服务器 xff0c 但是Git 更倾向于被使用于分布式模式 xff0c 也就是每个开发人员从中心版本库 服务器上chect out代
  • Android 9.0 SecureElementService 初始化流程分析

    1 相关名词解释 NFC Near Field Communication xff0c 近场通信 xff0c 一种基于13 56 MHz 的短距离通信技术 NFCC NFC Controller xff0c NFC 控制器 xff0c 负责
  • 【Linux】生产者消费者模型 - 详解

    目录 一 生产者消费者模型概念 1 为何要使用生产者消费者模型 2 生产者消费者之间的关系 3 生产者消费者模型的优点 二 基于阻塞队列的生产消费模型 1 在阻塞队列中的三种关系 2 BlockingQueue hpp 阻塞队列类 3 Lo
  • word 批量设置图片大小

    word批量修改图片大小 固定长宽篇 方法一 xff1a 这部分要说的是把word中的所有图片修改成固定的并且相同的长和宽 xff01 1 打开word xff0c 工具 xff0d 宏 xff0d 宏 xff08 或者直接按Alt 43
  • 深度学习之 人脸识别(1) 人脸预处理

    人脸识别分两个部分 xff1a 第一步 xff1a 人脸图片预处理 xff0c 即检测图片中人脸并裁剪成指定尺寸的人脸图 第二步 xff1a 人脸识别 xff0c 包括模型训练 目标人脸分类训练 预测目标人脸 1 人脸检测原理 人脸识别 x
  • 制作自己的个人网站方法

    随着个人创业的流行 xff0c 很多个人也需要一个比较详细的网站来展示自己 xff0c 开展个人业务 xff0c 或者积累粉丝等等 那么怎么制作自己的个人网站呢 xff1f 又该怎么制作得更个性好看 xff1f 下面就跟大家分享下制作方法
  • 傻瓜书,VMware里的Ubuntu

    转自 xff1a http bbs cnw com cn thread 136057 1 1 html 傻瓜书 xff0c VMware里的Ubuntu 0 预备知识 什么是Ubuntu 如果不了解这一点 xff0c 本文的内容似乎与您无关
  • 痞子衡单片机排行榜(2022Q4)

    痞子衡单片机排行榜 2022Q4 继2020年开办的 痞子衡嵌入式半月刊 之后 xff0c 从2023年1月份开始痞子衡将为大家带来新项目 痞子衡单片机排行榜 一年分四季 xff0c 每个季度发布一期 xff0c 以MCU主频和Corema
  • [pdf]使用spire读取PDF的文字和图片

    概述 最近在梳理某项目的数据标准 xff0c 从标准网下载了很多PDF格式的标准文件 xff0c 需要提取文字和图片 xff0c 所以写了个程序提取 xff1b 本文使用了免费版的Spire 约束 免费版的Spire一次只能提取PDF的10
  • JetPack系列之ViewBinding

    viewBinding的作用启用视图绑定Activity中使用视图绑定Framgent中使用视图绑定与findViewById相比 viewBinding的作用 启用视图绑定之后 xff0c 系统会为每个xml生成一个绑定类 xff0c 我
  • 正则表达式记录

    去掉所有非1到9或者字母的其它字符 private static String dealWithVersion String versionArg String regex 61 34 1 9a zA Z 34 versionArg 61
  • 批量kill掉带有某些标识的进程的shell命令

    微信公众号 xff1a WELTest 分享一个常用命令 xff0c 批量杀掉一批进程 xff0c 这里以tomcat为例 xff1a ps ef grep tomcat awk 39 print 2 39 xargs kill 9 命令解

随机推荐