REST API: Request body as JSON or plain POST data?

后端 未结 2 1700
盖世英雄少女心
盖世英雄少女心 2021-01-31 10:06

I\'m currently building a REST API. All GET methods currently use JSON as response format. Whats the best practice on POST and PUT operations? Use JSON in the request body or pl

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-31 10:14

    It depends on the data you want to exchange. If it is a complex structure you need to send it in a structured way (e.g. XML or JSON). In java web applications json is more lightweight, so it's preferable over XML.

    If you want to send a few fields from a form "application/x-www-urlformencoded" type could be used as well.

提交回复
热议问题