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/) ...
随机推荐
- Fast Scatter-Gather I/O
Some applications may need to read or write data to multiple buffers, which are separated in memory. ...
- Android wifi管理类:WifiAdmin
1.wifi的五种状态: WIFI_STATE_DISABLED WIFI网卡不可用 WIFI_STATE_DISABLING WIFI网卡正在关闭 WIFI_STATE_ENABLED ...
- [转载]应用 Valgrind 发现 Linux 程序的内存问题
应用 Valgrind 发现 Linux 程序的内存问题 如何定位应用程序开发中的内存问题,一直是 inux 应用程序开发中的瓶颈所在.有一款非常优秀的 linux 下开源的内存问题检测工具:valg ...
- springcloud +spring security多种验证方式之第三方token生成自己的token通过校验和自己的表单验证大体流程
步骤: 1.继承 WebSecurityConfigurerAdapter.class,其中使用两个过滤器,一个spring scurity自带的UsernamePasswordAuthenticat ...
- github基本命令
https://github.com/explore 使用github网站搜索资源 具体搜索 Git教程 - 廖雪峰的官方网站 一. git配置命令 1.设置用户名 git config --glob ...
- c#继承、多重继承
c#类 1.c#类的继承 在现有类(基类.父类)上建立新类(派生类.子类)的处理过程称为继承.派生类能自动获得基类的除了构造函数和析构函数以外的所有成员,可以在派生类中添加新的属性和方法扩展其功能.继 ...
- Python3中装饰器的使用
较为复杂的装饰器使用: user,passwd = 'hjc',111111 def auth(type): print('auth type:',type) def outwrapper(func) ...
- Info.plist文件配置及注意事项
1.Info.plist文件配置 常见配置 2.注意事项 Info.plist文件移动路径修改编译报错:could not read data from '/Users/lelight/Desktop ...
- UIStepper更加详细的图文理解
前言 UIStepper是一个微调器,该控件的外观和UISwitch相似,但该控件上包含了+,-两个按钮,共同用于控制某个值的增.减. 它继承了UIControl基类,默认属于活动控件,它可以与用户交 ...
- Win10每次开机总是自动弹出MSN网址导航如何取消
Win10每次开机总是自动弹出MSN网址导航如何取消 近来有用户在升级Win10系统后,每次开机总是会自动弹出MSN中文网的网址导航.如果不想要开机打开MSN网址导航,那么应该怎么设置来取消呢?对此, ...