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/) ...
随机推荐
- 【IMOOC学习笔记】多种多样的App主界面Tab实现方法(一)
1.ViewPager实现Tab 首先实现底部和底部布局 <?xml version="1.0" encoding="utf-8"?> <Li ...
- linux源码安装apache
apache安装之前,需要安装APR.APR-Util和PCRE依赖包 下载 Apache 下载地址: http://httpd.apache.org/download.cgi (打开找最 ...
- MVC异常的统一处理
禁用异常跟踪 很多时候异常是不可预料的,在每个Action方法或Controller上应用Exception Filter是不现实的.而且如果异常出现在View中也无法应用Filter.如RangeE ...
- ubuntu - 14.04,配置GOPATH(GO语言开发代码存放目录)
一,创建GOPATH:选择一个目录或者在我们想要的地方创建一个作为GOPATH的目录,我的GOPATH是:“/home/sunylat/gopath”. 二,配置系统变量:在shell里面输入“sud ...
- PHP里public和private的区别
public 公共的,谁都可以用 private 私有的,当前class可以随便用,外部不能调用
- Go语言学习教程:管理员登录功能开发
学习完了数据库操作的知识以后.本节内容,我们将实现管理员登陆功能,涉及到多个模块的代码实现和逻辑处理,以及数据库表的操作,都将在本节内容中进行实现. 管理员结构体定义 首先我们要定义管理员这个实体的结 ...
- 洛谷P2709 BZOJ 3781 小B的询问 (莫队)
题目描述 小B有一个序列,包含N个1~K之间的整数.他一共有M个询问,每个询问给定一个区间[L..R],求Sigma(c(i)^2)的值,其中i的值从1到K,其中c(i)表示数字i在[L..R]中的重 ...
- iOS自定义相机
1.首先声明以下对象 #import <AVFoundation/AVFoundation.h> //捕获设备,通常是前置摄像头,后置摄像头,麦克风(音频输入) @property (no ...
- appium中driver.wait报IllegalMonitorStateException的解释
在写appium代码的时候,有的人想使用wait方法,写成:driver.wait(),结果抛出异常:IllegalMonitorStateException,看了appium client的api文 ...
- HTML的知识点讲解(HTML版本)
老男孩培训机构老师的博客 1.html 2.css http://www.cnblogs.com/yuanchenqi/articles/6856399.html 3.javas ...