!/usr/bin/env python """ RESTful web.py testing usage: python webapp.py 8080 [--test] >>> req = app.request('/mathematicians', method='POST') >>> req.status '400 Bad Request' >>> name = {'first': 'Beno\xc3\xaet', 'last': 'Mandelbrot'} >>> data = urllib.urlencode(name) >>> req = app.request('/mathematicians', method='POST', data=data) >>> req.status '201 Created' >>> created_path = req.headers['Location'] >>> created_path '/mathematicians/b-mandelbrot' >>> fn = '<h1 class=fn>{0} {1}</h1>'.format(name['first'], name['last']) >>> assert fn in app.request(created_path).data """ import doctest import urllib import sys import web paths = ( '/mathematicians(/)?', 'Mathematicians', '/mathematicians/([a-z])-([a-z]{2,})', 'Mathematician' ) app = web.application(paths, globals()) dbname = {True: 'test', False: 'production'}[sys.argv[-1] == '--test'] db = {} # db = web.database(..., db='math_{0}'.format(dbname)) class Mathematicians: def GET(self, slash=False): """list all mathematicians and form to create new one""" if slash: raise web.seeother('/mathematicians') mathematicians = db.items() # db.select(...) return web.template.Template("""$def with (mathematicians) <!doctype html> <html> <head> <meta charset=utf-8> <title>Mathematicians</title> </head> <body> <h1>Mathematicians</h1> $if mathematicians: <ul class=blogroll> $for path, name in mathematicians: <li class=vcard><a class="fn url" href=/mathematicians/$path>$name.first $name.last</a></li> </ul> <form action=/mathematicians method=post> <label>First <input name=first type=text></label> <label>Last <input name=last type=text></label> <input type=submit value=Add> </form> </body> </html>""")(mathematicians) def POST(self, _): """create new mathematician""" name = web.input('first', 'last') key = '{0}-{1}'.format(name.first[0].lower(), name.last.lower()) name.first, name.last = name.first.capitalize(), name.last.capitalize() db[key] = name # db.insert(...) path = '/mathematicians/{0}'.format(key) web.ctx.status = '201 Created' web.header('Location', path) return web.template.Template("""$def with (path, name) <!doctype html> <html> <head> <meta charset=utf-8> <title>Profile Created</title> </head> <body> <p>Profile created for <a href=$path>$name.first $name.last</a>.</p> </body> </html>""")(path, name) class Mathematician: def GET(self, first_initial, last_name): """display mathematician""" key = '{0}-{1}'.format(first_initial, last_name) try: mathematician = db[key] # db.select(...) except KeyError: raise web.notfound() return web.template.Template("""$def with (name) <!doctype html> <html> <head> <meta charset=utf-8> <title>$name.first $name.last</title> </head> <body class=vcard> <p><a href=/mathematicians rel=up>Mathematicians</a> ▸</p> <h1 class=fn>$name.first $name.last</h1> </body> </html>""")(mathematician) if __name__ == "__main__": if sys.argv[-1] == '--test': doctest.testmod() else: app.run()
相关推荐
instrumented-restful-fast-request-pro-2023.1.7.1 可用版,亲测,可用。
软件源码模板资料.rar 00101.第1章内容介绍.flv 00303.项目介绍-项目概述.flv 00404.项目介绍-功能模块和业务流程.flv 00505.项目技术架构-软件架构的演进-从...01717.Nacos-服务发现-RESTful服务发现-客户端负载均衡
本资源类似于 Postman 的 IDEA 插件Restful Fast Request,在IDEA安装该插件后,找到插件安装目录,【C:\\Users\\Administrator\\AppData\\Roaming\\JetBrains\\IntelliJIdea2021.3\\plugins\\Restful Fast Request ...
spring-boot-web代码示例,是IDEA的项目工程,使用restful风格实现增删查改,静态数据
springboot2.4增删改查示例,结合B站尚硅谷教程使用,给初学者使用,spingboot2.4相较于1.5版本的用法有些变化,经验者绕行。
找到插件的安装目录如:C:\Users\work_\AppData\Roaming\JetBrains\IntelliJIdea2023.1\plugins\Restful Fast Request - API Buddy\lib 将附件中的jar包拖入替换. 此版本为最新版本 2023.2.1.1
去restopenapi go-restful软件包的扩展,面向以下Go字段标签已翻译为与OpenAPI等效的标签描述最低限度最大可选(如果设置为“ true”,则未在required列出) 独特型号说明类型(重写Go类型的String()) 枚举只读...
#基于Token及用户权限的Flask-Restful的Example 1. 以Token为认证 2. 拥有用户角色权限管理 #主要组成 1. Flask 2. Flask-Restful 3. Flask-SQlAlchemy 4. Flask-Security #其他可选方案 1. Flask-JWT & Flask-...
资源分类:Python库 所属语言:Python 资源全名:sanic_restful-0.0.9-py2.py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:FastApi-RESTful-0.2.4.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
Web Development with Go will teach you how to develop scalable real-world web apps, RESTful services, and backend systems with Go. The book starts off by covering Go programming language fundamentals ...
Metamorphic-Testing-of-RESTful-Web-APIs.pdf
This book provides a comprehensive introduction to Jersey framework (an implementation of JAX-RS specification) as the application development framework for RESTFul web service development. This book ...
资源来自pypi官网。 资源全名:flask-restful-swagger-3-0.2.0.tar.gz
Flask-RESTful Example 安装依赖包 python install -r requirements.txt 创建数据表 python manager.py db init python manager.py db migrate python manager.py db upgrade debug模式启动 python manager.py debug...
Java-RESTful-Web-Service.rar
python开发,基于flask-restful 的中小型项目,restful风格API接口开发实例,以mongodb作为数据库 python开发,基于flask-restful 的中小型项目,restful风格API接口开发实例,以mongodb作为数据库python开发,基于...
Building-RESTful-Python-Web-Services.pdf
Create-RESTful-API-使用-Node.js-Express-4 使用Node.js和Express 4创建RESTful API ##教程 ##要求 节点和npm ##安装 克隆仓库:git clone 安装依赖项:npm install 启动服务器:node server.js
blog-restful/ +-- .gitignore +-- .babelrc +-- .editorconfig +-- package.json +-- server.js +-- app ¦ +-- controllers ¦ ¦ +-- user.ctrl.js ¦ ¦ +-- post.ctrl.js ¦ +-- models ¦ ¦...