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. C++面试笔记--STL模板与容器

    1.C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器,更重要的是STL封装了许多复杂的数据结构算法和大量常用数据结构操作.vec ...

  2. java打成jar包后,class,getResource()出现null指针异常

    1.SqlHelper.java有包路径没?如果有,是不是类似于com.db.jdbc? 不管怎么办,你SqlHelper.class.getResourceAsStream("/mysql ...

  3. [译]Javascript中的错误信息处理(Error handling)

    本文翻译youtube上的up主kudvenkat的javascript tutorial播放单 源地址在此: https://www.youtube.com/watch?v=PMsVM7rjupU& ...

  4. C# 使用SendMessage 函数

    在C#中,程序采用了的驱动采用了事件驱动而不是原来的消息驱动,虽然.net框架提供的事件已经十分丰富,但是在以前的系统中定义了丰富的消息对系统的编程提供了方便的实现方法,因此在C#中使用消息有时候还是 ...

  5. Cookies的两种存取方式

    我们在使用webview开发时,少不了和cookie打交道,在网页端我这使用的是asp.net开发的,安卓下的cookie和windows平台下还是有些不同的,后来看了看,原来有两种cookie的存取 ...

  6. SqlServer压缩数据库日志

    )--数据库名称 )--数据库日志文件名称 --替换成自己的文件名称 select @dbName='dbname' select @dbNamelog='dbname_log' ) set @sql ...

  7. C# System.Timers.Timer定时器的使用和定时自动清理内存应用

    项目比较大有时候会比较卡,虽然有GC自动清理机制,但是还是有不尽人意的地方.所以尝试在项目启动文件中,手动写了一个定时器,定时清理内存,加快项目运行速度. public class Program { ...

  8. spark(2.1) - spark-shell 下文件系统的数据读写

    spark-shell 本地文件系统数据读写 [ file:// ] 读取 :sc.textFile (" ****") 写入:saveAsTextFile ("**** ...

  9. java基础之开发环境配置

    一. 环境变量配置的原理 一.  配置环境变量path 如果我们按照上面的来编译和运行的话未免太过于麻烦了,那么在这里我们可以配置环境变量PATH 1.配置环境变量的步骤 这时可以直接来看效果 如果d ...

  10. wget使用技巧

    以下内容为转载: wget 是一个命令行的下载工具.对于我们这些 Linux 用户来说,几乎每天都在使用它.下面为大家介绍几个有用的 wget 小技巧,可以让你更加高效而灵活的使用 wget. $ w ...