博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WSGI学习系列WSME
阅读量:4318 次
发布时间:2019-06-06

本文共 2841 字,大约阅读时间需要 9 分钟。

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, signaturefrom wsme.types import Fileimport bottlefrom 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 Pathroot = DemoRoot(webpath='/ws') # Add Soap protocolroot.addprotocol('soap',        tns='http://example.com/demo',        typenamespace='http://example.com/demo/types',        baseURL='http://127.0.0.1:8080/ws/',)# Add Rest Json protocalroot.addprotocol('restjson')# Create a wsgi Applicationbottle.mount('/ws/', root.wsgiapp())# Run Applicaton in bottlebottle.run()

转载于:https://www.cnblogs.com/edisonxiang/p/4724769.html

你可能感兴趣的文章
jenkins忘记密码如何处理?
查看>>
布尔操作符-逻辑或(||)
查看>>
vim的列编辑操作
查看>>
Linux驱动学习 —— 在/sys下面创建目录示例
查看>>
Linux下安装Android的adb驱动-解决不能识别的问题
查看>>
Why is the size of an empty class not zero in C++?
查看>>
海亮SC
查看>>
[Hibernate] - Generic Dao
查看>>
【Linux】一步一步学Linux——Linux系统常用快捷键(12) 待更新...
查看>>
Vue中computed和watch使用场景和方法
查看>>
laravel路由与控制器(资源路由restful)
查看>>
Html5移动端页面自适应布局详解(阿里rem布局)
查看>>
memoize-one在React中的应用
查看>>
SpringBoot整合JDBC数据库操作第二弹-配置基本数据库连接源
查看>>
nginx日志切割脚本
查看>>
ipvsadm添加虚拟服务器报错问题
查看>>
LVS-DR集群搭建脚本
查看>>
Docker拉取的镜像源更改为国内的镜像源
查看>>
LVS健康检查脚本
查看>>
PowerCLI 对vm批量关机
查看>>