目录

什么是 REST API?

REST API 也称为 RESTful API,是遵循 REST 架构规范的应用编程接口(API 或 Web API),支持与 RESTful Web 服务进行交互。REST 是表述性状态传递的英文缩写,由计算机科学家 Roy Fielding 创建。

如何实现 RESTful API?

API 要被视为 RESTful API,必须遵循以下标准:

  • 客户端-服务器架构由客户端、服务器和资源组成,并且通过 HTTP 管理请求。
  • 无状态客户端-服务器通信,即 get 请求间隔期间,不会存储任何客户端信息,并且每个请求都是独立的,互不关联。
  • 可缓存性数据:可简化客户端-服务器交互。
  • 组件间的统一接口:使信息以标准形式传输。这要求:
    • 所请求的资源可识别并与发送给客户端的表述分离开。
    • 客户端可通过接收的表述操作资源,因为表述包含操作所需的充足信息。
    • 返回给客户端的自描述消息包含充足的信息,能够指明客户端应该如何处理所收到的信息。
    • 超文本/超媒体可用,是指在访问资源后,客户端应能够使用超链接查找其当前可采取的所有其他操作。
  • 组织各种类型服务器(负责安全性、负载平衡等的服务器)的分层系统会参与将请求的信息检索到对客户端不可见的层次结构中。
  • 按需编码(可选):能够根据请求将可执行代码从服务器发送到客户端,从而扩展客户端功能。

虽然 REST API 需要遵循这些标准,但是仍比遵循规定的协议更容易,如 SOAP(简单对象访问协议),该协议具有 XML 消息传递、内置安全性和事务合规性等具体要求,因此速度较慢、结构繁重。

相比之下,REST 则是一组可按需实施的准则,使 REST API 速度更快、更轻,可扩展性更高,非常适合物联网(IoT)和移动应用开发。

人工智能服务

ChatGPT

{
    "status_code": 200,
    "status_info": "OK",
    "result": [
        {
            "object_type": "car",
            "confidence": 0.85,
            "bounding_box": {
                "x": 100,
                "y": 200,
                "width": 300,
                "height": 200
            }
        },
        {
            "object_type": "person",
            "confidence": 0.95,
            "bounding_box": {
                "x": 400,
                "y": 300,
                "width": 100,
                "height": 200
            }
        }
    ],
    "image_info": {
        "width": 800,
        "height": 600,
        "channels": 3
    }
}

Hugging Face

Object Detection

[
  {
    "score": 0.9964052438735962,
    "label": "person",
    "box": {
      "xmin": 422,
      "ymin": 65,
      "xmax": 643,
      "ymax": 495
    }
  },
  {
    "score": 0.9997736811637878,
    "label": "sports ball",
    "box": {
      "xmin": 94,
      "ymin": 445,
      "xmax": 175,
      "ymax": 517
    }
  }
]

ModelScope

DAMOYOLO-高性能通用检测模型-S

"root": {
  "detail": "",
  "code": 0,
  "computation_time": "0.16s",
  "data": {
    "boxes": [
      [
        42.50596237182617,
        134.0857391357422,
        229.2481231689453,
        410.7000732421875
      ],
      [
        377.09912109375,
        126.03817749023438,
        595.2017822265625,
        374.0760803222656
      ],
      [
        213.7623748779297,
        126.1344985961914,
        387.80377197265625,
        402.35455322265625
      ]
    ],
    "labels": [
      "person",
      "person",
      "person"
    ],
    "scores": [
      0.8726242184638977,
      0.8721222281455994,
      0.8559319972991943
    ]
  },
  "id": "838eb20e-4742-4831-b18c-a905ce0dba16",
  "msg": "",
  "queue": 0,
  "queue_time": 0,
  "status": 2
}

Microsoft Cognitive Services

Microsoft > Cognitive Services > Computer Vision API

{
  "objects": [
    {
      "rectangle": {
        "x": 0,
        "y": 0,
        "w": 50,
        "h": 50
      },
      "object": "tree",
      "confidence": 0.9,
      "parent": {
        "object": "plant",
        "confidence": 0.95
      }
    }
  ],
  "requestId": "1ad0e45e-b7b4-4be3-8042-53be96103337",
  "metadata": {
    "width": 100,
    "height": 100,
    "format": " Jpeg"
  },
  "modelVersion": "2021-04-01"
}

Azure > Cognitive Services > Computer Vision > Object detection

{
   "objects":[
      {
         "rectangle":{
            "x":730,
            "y":66,
            "w":135,
            "h":85
         },
         "object":"kitchen appliance",
         "confidence":0.501
      },
      {
         "rectangle":{
            "x":523,
            "y":377,
            "w":185,
            "h":46
         },
         "object":"computer keyboard",
         "confidence":0.51
      },
      {
         "rectangle":{
            "x":471,
            "y":218,
            "w":289,
            "h":226
         },
         "object":"Laptop",
         "confidence":0.85,
         "parent":{
            "object":"computer",
            "confidence":0.851
         }
      },
      {
         "rectangle":{
            "x":654,
            "y":0,
            "w":584,
            "h":473
         },
         "object":"person",
         "confidence":0.855
      }
   ],
   "requestId":"25018882-a494-4e64-8196-f627a35c1135",
   "metadata":{
      "height":473,
      "width":1260,
      "format":"Jpeg"
   },
   "modelVersion":"2021-05-01"
}

Azure > Cognitive Services > Vision Studio > Detect common objects in images

{
  "objectsResult": {
    "values": [
      {
        "boundingBox": {
          "x": 238,
          "y": 298,
          "w": 177,
          "h": 117
        },
        "tags": [
          {
            "name": "Skateboard",
            "confidence": 0.904
          }
        ]
      },
      {
        "boundingBox": {
          "x": 118,
          "y": 62,
          "w": 305,
          "h": 321
        },
        "tags": [
          {
            "name": "person",
            "confidence": 0.955
          }
        ]
      }
    ]
  },
  "modelVersion": "2023-02-01-preview",
  "metadata": {
    "width": 600,
    "height": 462
  }
}

Google Cloud Vision API

Vision AI

{
  "localizedObjectAnnotations": [
    {
      "boundingPoly": {
        "normalizedVertices": [
          {
            "x": 0.007744863,
            "y": 0.079945266
          },
          {
            "x": 0.9569666,
            "y": 0.079945266
          },
          {
            "x": 0.9569666,
            "y": 0.76662236
          },
          {
            "x": 0.007744863,
            "y": 0.76662236
          }
        ]
      },
      "mid": "/m/0hnnb",
      "name": "Umbrella",
      "score": 0.7512299
    },
    {
      "boundingPoly": {
        "normalizedVertices": [
          {
            "x": 0.39253283,
            "y": 0.27567247
          },
          {
            "x": 0.9210803,
            "y": 0.27567247
          },
          {
            "x": 0.9210803,
            "y": 0.9934403
          },
          {
            "x": 0.39253283,
            "y": 0.9934403
          }
        ]
      },
      "mid": "/m/01g317",
      "name": "Person",
      "score": 0.70294976
    }
  ]
}

AWS

Amazon Rekognition > Custom Labels Guide

Request

{
    "ProjectVersionArn": "string", 
     "Image":{ 
        "S3Object":{
            "Bucket":"string",
            "Name":"string",
            "Version":"string"
         }
    },
    "MinConfidence": 90,
    "MaxLabels": 10,
}

Response

{
    "CustomLabels": [
        {
            "Name": "MyLogo",
            "Confidence": 77.7729721069336,
            "Geometry": {
                "BoundingBox": {
                    "Width": 0.198987677693367,
                    "Height": 0.31296101212501526,
                    "Left": 0.07924537360668182,
                    "Top": 0.4037395715713501
                }
            }
        }
    ]
}

阿里云 X 达摩院

图像理解 > 物体检测

{
    "success": true,
    "data": {
        "data": {
            "RequestId": "A33CD921-3CAE-5BA5-8233-6B3F0C792265",
            "Data": {
                "Height": 533,
                "Elements": [
                    {
                        "Type": "dog",
                        "Score": 0.532,
                        "Boxes": [
                            205,
                            1,
                            417,
                            531
                        ]
                    }
                ],
                "Width": 948
            }
        },
        "url": "https://objectdet.cn-shanghai.aliyuncs.com/",
        "during": 356,
        "headers": {
            "response": {
                "date": "Wed, 05 Apr 2023 02:54:54 GMT",
                "content-type": "application/json;charset=utf-8",
                "content-length": "152",
                "connection": "keep-alive",
                "access-control-allow-origin": "*",
                "x-acs-request-id": "A33CD921-3CAE-5BA5-8233-6B3F0C792265",
                "x-acs-trace-id": "f1e1b9ee3bc9d270bd9339a5989e271f"
            }
        }
    },
    "requestId": "7914edd5-a415-4a5b-bb81-58bc537f3cc5"
}

腾讯云

图像识别 > 商品识别

{
    "Response": {
        "Products": [
            {
                "Name": "男士西服套装",
                "Parents": "服饰内衣-男装",
                "Confidence": 59,
                "XMin": 336,
                "YMin": 191,
                "XMax": 799,
                "YMax": 775
            },
            {
                "Name": "休闲鞋",
                "Parents": "鞋靴-时尚女鞋",
                "Confidence": 40,
                "XMin": 466,
                "YMin": 1209,
                "XMax": 695,
                "YMax": 1377
            }
        ],
        "RequestId": "2bd4243f-4d26-4246-a5f4-0f2dbc730d62"
    }
}

旷视 Face++

车牌识别 API

{
    "image_id": "ZZX0dA3yA+75FnXZ3lpDug==", 
    "request_id": "1524109138,f262f388-8562-4da1-9a9b-5de2cb05e50f", 
    "time_used": 1048, 
    "results": [
        {
            "color": 0, 
            "license_plate_number": "黑AF6655", 
            "bound": {
                "left_bottom": {
                    "y": 654, 
                    "x": 372
                }, 
                "right_top": {
                    "y": 416, 
                    "x": 1334
                }, 
                "right_bottom": {
                    "y": 645, 
                    "x": 1302
                }, 
                "left_top": {
                    "y": 424, 
                    "x": 404
                }
            }
        }
    ]
}

Eden AI

Eden AI 提供了一个连接到最佳人工智能引擎的独特 API。

Object Detection

{
  "api4ai": {
    "items": [
      {
        "label": "person",
        "confidence": 0.659053385257721,
        "x_min": 0.6336137056350708,
        "x_max": 0.827919602394104,
        "y_min": 0.4696902632713318,
        "y_max": 0.7678610384464264
      },
      {
        "label": "couch",
        "confidence": 0.455354243516922,
        "x_min": 0.4121762216091156,
        "x_max": 0.6568307876586914,
        "y_min": 0.4908463656902313,
        "y_max": 0.6873724162578583
      },
      {
        "label": "book",
        "confidence": 0.439803808927536,
        "x_min": 0.4353419542312622,
        "x_max": 0.49192070960998535,
        "y_min": 0.6771218180656433,
        "y_max": 0.7233667559921741
      }
    ]
  },
  "microsoft": {
    "items": [
      {
        "label": "couch",
        "confidence": 0.771,
        "x_min": 0.4140625,
        "x_max": 0.6510416666666666,
        "y_min": 0.5120370370370371,
        "y_max": 0.6990740740740741
      },
      {
        "label": "person",
        "confidence": 0.71,
        "x_min": 0.6541666666666667,
        "x_max": 0.840625,
        "y_min": 0.46944444444444444,
        "y_max": 0.7518518518518519
      },
      {
        "label": "couch",
        "confidence": 0.699,
        "x_min": 0.6692708333333334,
        "x_max": 0.9359375,
        "y_min": 0.5055555555555555,
        "y_max": 0.925
      }
    ]
  }
}

AI 提供商

参考资料