# 定义user类型和user列表类型

from wsme import types as wtypes

class User(wtypes.Base):
name = wtypes.text
age = int class Users(wtypes.Base):
users = [User]

#实现API逻辑

class UsersController(rest.RestController):

    @expose.expose(Users)
def get(self):
user_info_list = [
{
'name': 'Alice',
'age': 30,
},
{
'name': 'Bob',
'age': 40,
}
]
users_list = [User(**user_info) for user_info in user_info_list]
return Users(users=users_list)

转自: https://segmentfault.com/a/1190000004004179?utm_source=tuicool&utm_medium=referral

WSME api controller嵌套使用wtypes的更多相关文章

  1. Only one complex type allowed as argument to a web api controller action.

    错误内容: message":"An error has occurred.","exceptionMessage":"Only one c ...

  2. 重构Web Api程序(Api Controller和Entity)续篇

    昨天有写总结<重构Web Api程序(Api Controller和Entity)>http://www.cnblogs.com/insus/p/4350111.html,把一些数据交换的 ...

  3. MVC Controller 链接到 API Controller 以及反向链接

    MVC Controller 链接到 API Controller 以及反向链接 问题 想创建一个从 ASP.NET MVC controller 到 ASP.NET Web API controll ...

  4. 测试 ASP.NET Core API Controller

    本文需要您了解ASP.NET Core MVC/Web API, xUnit以及Moq相关知识. 这里有xUnit和Moq的介绍: https://www.cnblogs.com/cgzl/p/917 ...

  5. There is no action xxxFun defined for api controller api/subitem

    在使用abp的框架时,访问某个接口方法出现错误: There is no action xxxFun defined for api controller api/subitem 原因:肯定是访问的接 ...

  6. [水煮 ASP.NET Web API2 方法论](1-4)从 MVC Controller 链接到 API Controller 以及反向链接

    问题 想创建一个从 ASP.NET MVC controller 到 ASP.NET Web API controller 的直接链接,或者反向链接. 解决方案 可以使用 System.Web.Htt ...

  7. Rest Web Api Controller 返回JSON格式大小写

    public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.Ro ...

  8. Yii2 components api/controller

    When we wrote API, those controllers need to implement the following feature: 1. return JSON format ...

  9. ASP.NET Web API Controller 是怎么建成的

    先看ASP.NET Web API 讯息管线: 註:为了避免图片太大以至于超过版面,上图中的「HTTP 讯息处理程序」区块省略了 HttpRoutingDispatcher 处理路由分派的部分.「控制 ...

随机推荐

  1. bash 脚本编程 利用 “=” 赋值时,左右不能留空格

    对脚本变量用“=”赋值时, "=" 左右不能留有空格,否则会提示错误. 比如以下例子: #!/bin/bash BEGIN_TIME = `date +%H:%M:%S` ./a. ...

  2. LintCode-Longest Increasing Subsequence

    Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...

  3. RSA加密算法的java实现

    package rsa; import java.security.*;import java.security.interfaces.*;import javax.crypto.*; public ...

  4. ModernUI教程:如何使用你自己的导航框架

         Modern UI for WPF带有一个内置的页面导航框架,易于使用和可扩展的.但这并不是必须的,你也可以自己来自定义一个导航框架.      默认的ModernWindow控件模板包括标 ...

  5. 处理 pcap 中的 mac 二进制字节流为可读格式

    import struct # 利用 struct 处理字节流中的mac地址 适用于小端地址操作系统 def mac2str(bi_mac): mac = "" for i in ...

  6. PowerDesigner逆向工程导入MYSQL数据库总结

    由于日常数据建模经常使用PowerDesigner,使用逆向工程能更加快速的生成模型提高效率,所以总结使用如下: 首先现在PowerDesigner,这里提供PD16.5版本链接: http://pa ...

  7. python day1:初识Python(一)

    一.Python 简介: Python免费.开源,面向对象的解释型语言,其语法简洁,在使用中无需考虑如何管理内存等底层问题,并且支持在linux,windows等多平台运行,Python的标准库很强大 ...

  8. OpenLayers的定制

    最近因为工作的需要,把主流的的一些GIS的javascript库看了一遍,主要是ArcGIS Server API for Javascript,Openlayers和Leaflet. 先说说ArcG ...

  9. 解决:dpkg:处理 xxx (--configure)或E: Sub-process /usr/bin/dpkg returned an error code (1)

    问题重现: 问题解决办法: #先备份原来的,然后重新新建 sudo mv /var/lib/dpkg/info /var/lib/dpkg/info.bak //现将info文件夹更名 sudo mk ...

  10. zookeeper系列之通信模型(转)

    本文的主题就是讲解Zookeeper通信模型,本节将通过一个概要图来说明Zookeeper的通信模型. Zookeeper的通信架构 在Zookeeper整个系统中,有3中角色的服务,client.F ...