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的更多相关文章

  1. WSGI学习系列WebOb

    1. WSGI Server <-----> WSGI Middleware<-----> WSGI Application  1.1 WSGI Server wsgi ser ...

  2. WSGI学习系列Paste

    Paste has been under development for a while, and has lots of code in it. The code is largely decoup ...

  3. WSGI学习系列多种方式创建WebServer

    def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) ...

  4. WSGI学习系列eventlet.wsgi

    WSGI是Web Service Gateway Interface的缩写. WSGI标准在PEP(Python Enhancement Proposal)中定义并被许多框架实现,其中包括现广泛使用的 ...

  5. WSGI学习系列Pecan

    Pecan Introduce Pecan是一个轻量级的基于Python的Web框架, Pecan的目标并不是要成为一个“full stack”的框架, 因此Pecan本身不支持类似Session和D ...

  6. 分布式学习系列【dubbo入门实践】

    分布式学习系列[dubbo入门实践] dubbo架构 组成部分:provider,consumer,registry,monitor: provider,consumer注册,订阅类似于消息队列的注册 ...

  7. Entity Framework Code First学习系列目录

    Entity Framework Code First学习系列说明:开发环境为Visual Studio 2010 + Entity Framework 5.0+MS SQL Server 2012, ...

  8. WCF学习系列汇总

    最近在学习WCF,打算把一整个系列的文章都”写“出来,包括理论和实践,这里的“写”是翻译,是国外的大牛写好的,我只是搬运工外加翻译.翻译的不好,大家请指正,谢谢了.如果觉得不错的话,也可以给我点赞,这 ...

  9. EF(Entity Framework)系统学习系列

    好久没写博客了,继续开启霸屏模式,好了,废话不多说,这次准备重新系统学一下EF,一个偶然的机会找到了一个学习EF的网站(http://www.entityframeworktutorial.net/) ...

随机推荐

  1. js/jq基础(日常整理记录)-1-纯js格式化时间

    一.纯js格式化时间 之前记录了一些,工作中发现的比较常用的使用,就记录一下. 由于很基础,就直接贴出来了,不做分析了. 改造一下Date的原型 Date.prototype.format = fun ...

  2. mybatis spring maven

    maven版本:3.3.9  解压即可使用 spring版本:4.3.9  通过maven进行管理下载 mybatis版本:3.4.4 通过maven进行管理下载 mysql版本:5.7  conne ...

  3. C#利用phantomJS抓取AjAX动态页面

    在C#中,一般常用的请求方式,就是利用HttpWebRequest创建请求,返回报文.但是有时候遇到到动态加载的页面,却只能抓取部分内容,无法抓取到动态加载的内容. 如果遇到这种的话,推荐使用phan ...

  4. ASP.NET-GridView之固定表数据滚动

    有时候,在线Web开发时,需要显示的数据往往会超过我们规定的表格长度,所以为了方便显示大量数据,为了美观,这里提出了两种显示数据方式. ①可以滚动显示数据但是表头未能获取 效果显示 前端DEMO &l ...

  5. windows 注册表

    注册表(Registry,繁体中文版Windows称之为登录)是Microsoft Windows中的一个重要的数据库,用于存储系统和应用程序的设置信息.早在Windows 3.0推出OLE技术的时候 ...

  6. 洛谷P2900 [USACO08MAR]土地征用Land Acquisition(斜率优化)

    题意 约翰准备扩大他的农场,眼前他正在考虑购买N块长方形的土地.如果约翰单买一块土 地,价格就是土地的面积.但他可以选择并购一组土地,并购的价格为这些土地中最大的长 乘以最大的宽.比如约翰并购一块3 ...

  7. luogu2948 滑雪课

    题解里面全是dp的大神本蒟蒻瑟瑟发抖奉上一篇记忆化搜索... 其实嘛,记忆化搜索还是很安全透彻清真人品的,一般递推不好实现dp可以用记忆化搜索 然后本题先预处理一个mint[i]代表当前能力值为i,参 ...

  8. 公有云Docker镜像P2P加速之路:安全篇

    一.问题 在使用Docker运行容器化应用时,宿主机通常先要从Registry服务(如Docker Hub)下载相应的镜像(image).这种镜像机制在开发环境中使用还是很有效的,团队成员之间可以很方 ...

  9. filter防止xxs攻击

    什么是XSS攻击? XSS攻击使用Javascript脚本注入进行攻击 例如在表单中注入: <script>location.href='http://www.itmayiedu.com' ...

  10. 在线作图工具 Flowchart Maker & Online Diagram Software & Visual Solution

    9款国内外垂直领域的在线作图工具:那些可以替代Visio的应用!-CSDN.NEThttps://www.csdn.net/article/2015-02-12/2823939 Documentsht ...