dpno17028 2015-10-30 20:41
浏览 37

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

I am new to developing webservice, my idea is to build a REST API based on PHP. Which make possible to CRUD images files e.g. images/test.jpg.

Is possible to get images over a REST webservice? If yes, then how? Or is a webservice only for json responses provided?

I prefer approach without a framework, because i want to learn.

My routes:

// 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 Response example

  /api/images/1

Version the image file itself stored phyisical on webservice project(www.example.com).

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

or be better this version

Version the image itself stored phyisical on frontend project(www.example-frontend.com).

{
    "filename": "example.jpg",
    "filepath": "images/example.jpg",
    "htmlAlt": "Example Image",
}
  • 写回答

1条回答 默认 最新

  • dongmanni6916 2015-10-30 21:25
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退