AppEngine 的 RESTFul 服务框架 [英] RESTFul Service Framework for AppEngine

查看:23
本文介绍了AppEngine 的 RESTFul 服务框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开展一个项目,该项目涉及使用 Google AppEngine PAAS 的移动和网络客户端.我想在我的 AppEngine 应用中使用 RESTFul 网络服务.

我查看了 Stackoverflow 中对 RESTFul 服务框架的引用,这些框架可与 AppEngine 一起用于 Web (GWT) 和移动 (Android) 客户端.尽管 Restlet 似乎为 AppEngine、GWT 和 Android 提供了版本,但到目前为止我已经把它归结为 RestEasy 主要是由于这个 问题.

之前有一些问题讨论 RESTFul 框架,但我认为这些比较并不适用对此,现在很常见的情况.听取经验丰富的开发人员对适用于这组平台的框架的看法以及每个平台的优缺点会很有帮助.

解决方案

您可能希望考虑使用 Google Cloud Endpoints,它在 Google I/O 上被宣布为 App Engine 的可信测试器功能,现在可供所有人使用.使用 Endpoints,您可以注释简单的 Java(或 Python)类和方法来描述您的 API.例如,这是一个简单的类,用于从井字游戏中获取和检索高分列表:

@Api(name = "tictactoe")公共类 ScoreEndpoint {@ApiMethod(name = "scores.get")public Sc​​ore get(@Named("id") String id) {PersistenceManager pm = getPersistenceManager();分数 score = pm.getObjectById(Score.class, id);下午.关闭();返回分数;}@ApiMethod(name = "scores.list")公开列表列表() {PersistenceManager pm = getPersistenceManager();查询查询 = pm.newQuery(Score.class);return (List) pm.newQuery(query).execute();}}

特点

  • 支持 Java 和 Python 运行时
  • 建立在 Google 的 API 基础架构之上 - 它可以与许多用于 Google 自己的 API 的相同工具和库配合使用,例如 APIs ExplorerAPIs Console
  • 自动生成的、静态类型的 Android 和 iOS 客户端库 - 这些库使用相同的 Google 创作的 JavaObjective-C 库,可用于访问其他 Google 提供的 API,例如日历 API
  • 动态类型的 JS 客户端库 - 同样,您在 JS 中用于访问其他 Google 提供的 API 的库
  • 支持 OAuth 2
  • 与适用于 Eclipse 的 Google 插件集成 - 这使您可以根据模型自动创建 API,或创建支持现有 Android 应用的 App Engine 应用
  • 支持本地开发 - 您可以使用 App Engine 开发环境构建和测试您的 API,就像使用其他 App Engine 功能一样

了解更多

查看文档,了解有关使用 Endpoints 的更多详细信息.>

您还可以观看来自 Google I/O 的几场演讲:

I am working on a project that involves mobile and web clients with Google's AppEngine PAAS. I would like to use RESTFul webservices with my AppEngine app.

I have looked over Stackoverflow for references to RESTFul service frameworks that can be used with AppEngine for both web (GWT) and mobile (Android) clients. Although Restlet seems to provide editions for AppEngine, GWT and Android, so far I've got it down to RestEasy mostly due to this question.

There have been questions previously that discuss RESTFul frameworks but I don't think the comparisons apply well to this, now quite common, case. It would be helpful to hear experienced developers' views on the frameworks available for this set of platforms and merits versus demerits of each.

解决方案

You might wish to consider using Google Cloud Endpoints, which was announced as a trusted tester feature for App Engine at Google I/O, and is now available to everyone. With Endpoints, you annotate simple Java (or Python) classes and methods to describe your API. For example, this is a simple class to get and retrieve a list of high scores from a Tic Tac Toe game:

@Api(name = "tictactoe")
public class ScoreEndpoint {
  @ApiMethod(name = "scores.get")
  public Score get(@Named("id") String id) {
    PersistenceManager pm = getPersistenceManager();
    Score score = pm.getObjectById(Score.class, id);
    pm.close();
    return score;
  }

  @ApiMethod(name = "scores.list")
  public List<Score> list() {
    PersistenceManager pm = getPersistenceManager();
    Query query = pm.newQuery(Score.class);
    return (List<Score>) pm.newQuery(query).execute();
  }
}

Features

  • Support for Java and Python runtimes
  • Built on Google's API infrastructure - it works with many of the same tools and libraries used for Google's own APIs, such as the APIs Explorer and APIs Console
  • Automatically-generated, statically-typed client libraries for Android and iOS - these libraries are using the same Google-authored Java and Objective-C libraries you would use to access other Google-provided APIs such as the Calendar API
  • Dynamically-typed JS client library - again, the same library you use to access other Google-provided APIs in JS
  • Built in support for OAuth 2
  • Integration with the Google Plugin for Eclipse - this allows you to automatically create an API based on a model, or an App Engine application to back an existing Android app
  • Support for local development - you can build and test your API using the App Engine development environment, just as with other App Engine features

Learn More

Check out the documentation for more details on using Endpoints.

You can also watch several talks from Google I/O:

这篇关于AppEngine 的 RESTFul 服务框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆