WSGI学习系列WSME
Introduction
Web Services Made Easy (WSME) simplifies the writing of REST web services by providing simple yet powerful typing,
removing the need to directly manipulate the request and the response objects.
Protocols
WSEM support lots of protocols.
'restjson': Implements a REST+Json protocol.
'restxml': Implements a REST+Xml protocol.
'soap': Implements the SOAP protocol.
Conception
WSRoot: Root controller for webservices
@expose: The return type of web service interface
@validate: Validate the incoming paramters type
@signature: Set the return type and the incoming paramters type
Example
WSME provide details implements for Web Service.
WSME need a Web Framework to provide service.
In the OpenStack, Horizon use Django web framework.
The following example use bottle web framework.
from wsme import WSRoot, expose, validate, signature
from wsme.types import File import bottle
from six import uclass Person(object):
id = int
firstname = unicode
lastname = unicode hobbies = [unicode] def __repr__(self):
return "Person(%s, %s %s, %s)" % (
self.id,
self.firstname, self.lastname,
self.hobbies
) class DemoRoot(WSRoot):
@expose(int)
@validate(int, int)
def multiply(self, a, b):
return a * b @expose(File)
@validate(File)
def echofile(self, afile):
return afile @expose(unicode)
def helloworld(self):
return u"Здраво, свете (<- Hello World in Serbian !)" @expose(Person)
def getperson(self):
p = Person()
p.id = 12
p.firstname = u'Ross'
p.lastname = u'Geler'
p.hobbies = []
print p
return p @expose([Person])
def listpersons(self):
p = Person()
p.id = 12
p.firstname = u('Ross')
p.lastname = u('Geler')
r = [p]
p = Person()
p.id = 13
p.firstname = u('Rachel')
p.lastname = u('Green')
r.append(p)
print r
return r @expose(Person)
@validate(Person)
def setperson(self, person):
return person @expose([Person])
@validate([Person])
def setpersons(self, persons):
print persons
return persons @signature(int, int, int)
def increment(self, value, delta=1):
return value + delta @signature(Person, body=Person)
def updateauthor(self, person):
return person
# Set Web Root Path
root = DemoRoot(webpath='/ws')
# Add Soap protocol
root.addprotocol('soap',
tns='http://example.com/demo',
typenamespace='http://example.com/demo/types',
baseURL='http://127.0.0.1:8080/ws/',
)
# Add Rest Json protocal
root.addprotocol('restjson')
# Create a wsgi Application
bottle.mount('/ws/', root.wsgiapp())
# Run Applicaton in bottle
bottle.run()
WSGI学习系列WSME的更多相关文章
- WSGI学习系列WebOb
1. WSGI Server <-----> WSGI Middleware<-----> WSGI Application 1.1 WSGI Server wsgi ser ...
- WSGI学习系列Paste
Paste has been under development for a while, and has lots of code in it. The code is largely decoup ...
- WSGI学习系列多种方式创建WebServer
def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) ...
- WSGI学习系列eventlet.wsgi
WSGI是Web Service Gateway Interface的缩写. WSGI标准在PEP(Python Enhancement Proposal)中定义并被许多框架实现,其中包括现广泛使用的 ...
- WSGI学习系列Pecan
Pecan Introduce Pecan是一个轻量级的基于Python的Web框架, Pecan的目标并不是要成为一个“full stack”的框架, 因此Pecan本身不支持类似Session和D ...
- 分布式学习系列【dubbo入门实践】
分布式学习系列[dubbo入门实践] dubbo架构 组成部分:provider,consumer,registry,monitor: provider,consumer注册,订阅类似于消息队列的注册 ...
- Entity Framework Code First学习系列目录
Entity Framework Code First学习系列说明:开发环境为Visual Studio 2010 + Entity Framework 5.0+MS SQL Server 2012, ...
- WCF学习系列汇总
最近在学习WCF,打算把一整个系列的文章都”写“出来,包括理论和实践,这里的“写”是翻译,是国外的大牛写好的,我只是搬运工外加翻译.翻译的不好,大家请指正,谢谢了.如果觉得不错的话,也可以给我点赞,这 ...
- EF(Entity Framework)系统学习系列
好久没写博客了,继续开启霸屏模式,好了,废话不多说,这次准备重新系统学一下EF,一个偶然的机会找到了一个学习EF的网站(http://www.entityframeworktutorial.net/) ...
随机推荐
- UCOSIII五种状态
休眠态:未用OSTaskCreate创建任务,不受UCOS管理 就绪态:在就绪表中已经登记,等待获取CPU使用权 运行态:已经获取CPU使用权并运行的任务 等待态:暂时让出CPU使用权,等待某一事件触 ...
- angularjs+requlirejs 搭建前端框架(1)
第一部分:发发牢骚吧 随着富前端时代的逐渐深入,越来越多的前端技术框架层出不穷,可以说是百花齐放.让我们这些爱好前端的人疲于奔命,今天学习这个框架,明天研究那个框架,哎,说不出的蛋疼...感觉好累.. ...
- 动态变更Repeater控件HeaderTemplate列名
本博文,Insus.NET教你动态实现变更Repeater控件HeaderTemplate列名.一般情况之下,是不需要动态变更,只有动态有Repeater控件不变情况之下,来显示多种数据源进行绑定.这 ...
- JVM各区域的用途
程序计数器 用于给字节码解释器来选取吓一跳需要执行的字节码指令.每个线程有一个独立的程序计数器去,且各个线程之间互不影响.如果线程正在执行一个Java方法,这个计数器记录的是正在执行的虚拟机字节码指令 ...
- Mybatis+maven自动构建dao、mapper、model
1.Pom.xml文件配置: 代码: <plugins> <!-- Mybatis generator代码生成插件 配置 --> <plugin> <grou ...
- TensorFlow创建变量
1 使用tf.Variable函数创建变量 tf.Variable(initial_value=None,trainable=True,collections=None,validate_shape= ...
- UINavigationController + UIScrollView组合,视图尺寸的设置探秘(一)
UINavigationController和UIScrollView是iOS下几种主要的交互元素,但当我搭配二者在一起时,UIScrollView的滚动区域出现了很诡异的现象.我希望UIScroll ...
- [转]10分钟梳理MySQL知识点:揭秘亿级高并发数据库调优与最佳实践法则
转:https://mp.weixin.qq.com/s/RYIiHAHHStIMftQT6lQSgA 做业务,要懂基本的SQL语句: 做性能优化,要懂索引,懂引擎: 做分库分表,要懂主从,懂读写分离 ...
- 【转】oracle远程导入数据库
源地址:http://blog.chinaunix.net/uid-20980141-id-447996.html
- MobaXterm替换cmder
Windows上命令行工具cmder确实很好用,其扩展功能呢,比系统自带强大几倍.后来在使用MobaXterm,官网https://mobaxterm.mobatek.net/免费版本功能足够强大,支 ...