What type of API is this?

2019-06-14 03:53发布

Create a very simple form (no styling required) on your own environment to
integrate into our Webservice API using 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.

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

My following code works for validating the form:

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]

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

What kind of service am I connecting to?

My request headers:

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

The response headers:

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

I get the response formatted in XML:

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

Is it SOAP , REST, neither or unknown?

标签: php api rest soap
2条回答
做个烂人
2楼-- · 2019-06-14 04:16

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

查看更多
仙女界的扛把子
3楼-- · 2019-06-14 04:37

I'd like to say that it's unknown. You can't say that REST use only JSON format because it can also use XML. IMO you can say that's endpoint which return some data in XML format.

查看更多
登录 后发表回答