REST API图像链接的最佳做法

问题描述 投票:1回答:0

我正在研究REST API,我想知道在填充图像URL时有什么更好的方法。

就我而言,我想根据图像出现的位置以不同的尺寸填充图像。例如,在某些地方,我希望图像显示为50 x 50像素。 但是,在其他地方,我希望它显示为500 x 500像素。

我创建了一个函数DrawImage(ImageSRC, width) ,该函数根据提供的宽度在.NET中使用System.Drawing重建图像。 这样,每当我实际上不需要加载大图像时,我将使用50 x 50 px的图像而不是500 x 500 px的图像。

我的问题是,什么是更好的方法?


方法1(传统方法):在REST API中提供完整的图像路径并在代码中处理图像重建:

REST API

[{
    "title": "Article title",
    "image": "http://somdomain.com/PathToImage/ImageName.png"
}]


码:

ImageSrc = "http://somdomain.com/PathToImage/ImageName.png";
Width = 50;
<img alt="" src="DrawImage(ImageSRC, width)" />

// Or image population can be like this:
//<img alt="" src="http://somdomain.com/PageThatCallsTheFunctionDrawImage" />

方法2:在REST API中将图像的值作为函数提供,并且参数由以下API传递:

REST API

[{
    "title": "Article title",
    "image": "DrawImage('http://somdomain.com/PathToImage/ImageName.png', 50)"
}]


码:

VALUE_OF_IMAGE_IN_API = DrawImage("http://somdomain.com/PathToImage/ImageName.png", 50);

<img alt="" src="VALUE_OF_IMAGE_IN_API" />
vb.net rest web-services wcf api-design
© www.soinside.com 2019 - 2024. All rights reserved.