什么类型的API,这是? [英] What type of API is this?

查看:116
本文介绍了什么类型的API,这是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在自己的环境中创建一个非常简单的形式(无需造型)到

  集成到使用HTTP POST我们的web服务的API。

Create a very simple form (no styling required) on your own environment to
integrate into our Webservice API using HTTP POST.

我写了使用简单的应用程序的 Zend框架2 。该应用程序创建,一旦验证的形式被发送到了通过HTTP POST Web服务器API 的收到回复。

I have written a simple application using Zend Framework 2. The application creates a form that once validated is to be sent to a "Webserver API via HTTP POST" to receive a response.

我想查询API以正确的方式,因为我在协议和标准非常多的信徒。

I would like query the API in the correct way as I am very much a believer in protocols and standards.

我的下code工程验证表单:

zf-skeleton/module/MyApplication/src/MyApplication/Controller/IndexController.php

public function submitAction() {
     $myForm = new MyForm();
     $myForm->get('submit')->setValue('Add');         

     $request = $this->getRequest();
     if ($request->isPost()) {
         $myModel = new MyModel();
         $myForm->setInputFilter($myModel->getInputFilter());
         $myForm->setData($request->getPost());

         if ($myForm->isValid()) {
             // Form is validated. [1]

一旦表单被验证我想知道的最佳方式将表单数据发送到的通过HTTP POST Web服务器API 的,并处理响应

我的请求报头:

GET /api?foo=1&bar=2 HTTP/1.1
Host: [theservice]
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:39.0) Gecko/20100101 Firefox/39.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: [my cookies]
Connection: keep-alive

的响应标头:

HTTP/1.1 200 OK
Date: Tue, 23 Feb 2016 12:58:18 GMT
Content-Type: text/xml
Content-Length: 343
Connection: keep-alive
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: [Cookie data]
Vary: Accept-Encoding
Content-Encoding: gzip
Server: cloudflare-nginx

如果我把我的浏览器:

http://theservice/api?foo=1&bar=2

我得到XML格式的响应:

I get the response formatted in XML:

<response>
    <validresponse>YES</validresponse>
    <foo>21</foo>
    <bar>21</bar>
</response>

它是SOAP,REST,既不或未知

推荐答案

休息时可以产生响应的无论是在XML和JSON 。因此,我们不一定能排除REST。
这是非常REST在我看来。

Rest can generate response both in xml and json. So we cannot rule out REST necessarily. It is very REST in my opinion.

这篇关于什么类型的API,这是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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