我是开发Web服务的新手,我的想法是基于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
对网络服务项目(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",
}
最佳答案
Is possible to get images over a REST webservice?
是的。
If yes, then how?
您向表示图像的 URL 发出 GET 请求。服务器发回图像。
(所述服务器还可能支持上传新图像的 PUT 请求、删除图像的 DELETE 请求等)。
Or is a webservice only for json responses provided?
网络服务提供其作者想要提供的任何类型的数据。
关于PHP REST API Webservice 与图像的正确使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33444562/