指导编写的包装的REST API [英] Guidance for writing a wrapper for a REST API

查看:145
本文介绍了指导编写的包装的REST API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了围绕REST和更少的结构化的Web界面了一些非常随意的包装,但都只是玩玩而已,很少注意错误检测和处理,超时等。

I've written a few very casual wrappers around REST and less structured web interfaces, but all just for fun, with very little attention to error detection and handling, timeouts, etc.

有人可以请给我一些指点,无论是在行为或资源,开发一个坚实的,专业的.NET(或其他平台)包装的REST API?

Can somebody please give me some pointers, either on practices, or to resources, for developing a solid, professional .NET (or other platform) wrapper for a REST API?

这过我的脑海的事情是:

Things that cross my mind are:


  1. 国米preting HTTP错误codeS和过滤协议从API错误的错误。

  2. 根据大厦的URL请求,可能与模式匹配和令牌替换。

  3. 匹配后背上请求。

  4. 如何映射一个面向对象的模型,以REST模型。某些请求适合静态方法,例如越来越名单,和其他人在中间的静态和实例,也许一个简单的供应商之间的模式与挂所有静态方法?

新:我自从发现了这个几乎是太基本指南,使雅虎REST调用的,但它可以作为一个起点。

NEW: I've since found this almost too basic guide to making Yahoo REST calls, but it serves as a starting point.

重要: 一个非常复杂的,很少涉及的方面是如何处理的REST API窗体身份验证。单独的登录请求,饼干存储等。

推荐答案

虽然我在一个面向对象的上下的方式已经包裹了无数的Web服务,我觉得拿出一个很好的回答你的问题很难。

Although I have wrapped countless web services in an OOP-ish way, I find it difficult to come up with a good answer to your question.

一对夫妇的雅虎API的例子可以在这里找到:<一href=\"http://curlobjects.com/trac/browser/trunk/lib/YahooApi\">http://curlobjects.com/trac/browser/trunk/lib/YahooApi

A couple of Yahoo API examples can be found here: http://curlobjects.com/trac/browser/trunk/lib/YahooApi

1国米preting HTTP错误codeS和过滤协议从API错误
  错误。

1 Interpreting HTTP error codes and filtering protocol errors from API errors.

我的基本HTTP类具有HTTP错误回调,可以覆盖。

My base http class has an http error callback that can be overriden.

2基于建筑URL请求,可能与模式匹配和
  令牌替换。

2 Building URL based requests, possibly with pattern matching and token substitution.

我preFER字符串连接。

I prefer string concatenation.

4如何映射一个面向对象的模型,以REST模型。某些请求适合静态
  方法,例如获取列表,并
  他人在之间的中部挂
  静态和实例,也许一个普通的
  与所有供应商的静态模式
  方法是什么?

4 How to map an OO model to the REST model. Some requests suit static methods, e.g. getting lists, and others hang in the middle between static and instance, maybe a plain provider pattern with all static methods?

有时你需要一个大的静态工厂/供应商,有时你想为每个方法的类,有时一个班的每个组的相关方法......真的是不走这一个正确的方法。我总是花一些时间去服务的结构的感受,然后试图找到一种优雅的方式来抽象重复的部分。

Sometime you need one big static factory/provider, sometimes you want a class for each method, sometimes a class for each group of related methods... There really isn't one proper way to go about this. I always spend some time getting a feel of the service's structure and then try to find an elegant way to abstract the repetitive parts.

如果您有关于登录表单,饼干等有更具体的问题,我很乐意回答他们。

If you have any more specific questions regarding login forms, cookies, etc, I'd be glad to answer them.

编辑:

HttpWebRequest的提到,我猜你要么需要设置<一个href=\"http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.clientcertificates.aspx\">ClientCertificate物业,并使用SSL得当,也可以忽略所有SLL错误与CertificatePolicy

HttpWebRequest was mentioned and I'm guessing you either need to set the ClientCertificate property and use SSL properly, or you can ignore all SLL errors with a CertificatePolicy.

这篇关于指导编写的包装的REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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