Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

If you expose a Rest API, are you also supposed to provide the DTOs in popular languages?

If I expose a Rest end point that anyone can consume. For argument sake let's say it accepts a ticker symbol and I return a json string that has information on that, for example the ceo, stock price and year founded.

{
  "symbol": "Abc",
  "ceo": "Elon Musket",
  "stock price": "$50",
  "year founded": "2023"
}

Am I supposed to provide DTOs that can be consumed in Java, C# and other popular languages (for deserializing)? Is that a common practice? Or anyone who consumes my service is supposed to create their own DTOs?

question from:https://stackoverflow.com/questions/65865096/if-you-expose-a-rest-api-are-you-also-supposed-to-provide-the-dtos-in-popular-l

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

A DTO (Data Transfer Object) is a design pattern for any object used to transfer multiple data values between remote systems. JSON is a DTO, which is handled just fine by pretty much every language that would be able to receive it.

If you are worried about best REST API practices, check out the stackoverflow page on the exact topic.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...