PHP REST API Web服务正确使用图像?

时间:2015-10-30 20:41:14

标签: php web-services rest

我是开发webservice的新手,我的想法是构建一个基于PHP的REST API。 这使得CRUD图像文件成为可能,例如图像/ test.jpg放在。

是否可以通过REST Web服务获取图像?如果是,那怎么样? 或者仅提供json响应的Web服务?

我更喜欢没有框架的方法,因为我想学习。

我的路线:

// GET
/api/images  # Get alle images
/api/images/1 # Get images based on primary key

// PUT
/api/images/1 # Update images based on primary key

// POST
/api/images # Add a new image

// DELETE
/api/images/1 # Delete images based on primary key

JSON响应示例

  /api/images/1

版本图像文件本身存储在webservice项目(www.example.com)上。

{
    "filename": "example.jpg",
    "filepath": "www.example.com/images/example.jpg",
    "htmlAlt": "Example Image",
}

或者这个版本更好

版本图像本身存储在前端项目(www.example-frontend.com)上的物理上。

{
    "filename": "example.jpg",
    "filepath": "images/example.jpg",
    "htmlAlt": "Example Image",
}

1 个答案:

答案 0 :(得分:-1)

Is possible to get images over a REST webservice?

Yes.

If yes, then how?

You make a GET request to the URL which represents the image. The server sends back an image.

(Said server might also support PUT requests to upload new images, DELETE requests to remove them, and so on).

Or is a webservice only for json responses provided?

A webservice provides whatever kind of data its author wants to provide.