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

查看:18
本文介绍了这是什么类型的 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 Framework 2 编写了一个简单的应用程序.应用程序创建一个表单,一旦验证将发送到Webserver API via HTTP POST"以接收响应.

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.

我的以下代码用于验证表单:

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]

一旦表单经过验证,我想知道将表单数据发送到Webserver API via HTTP POST"并处理响应的最佳方式

Once the form has been validated I would like to know the best way to send the form data to the "Webserver API via HTTP POST" and handle the response

我的请求标头:

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

如果我在浏览器中输入:

If I put into my browser:

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,两者都不是或未知?

推荐答案

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天全站免登陆