raiz
V2EX  ›  问与答

web api 设计中, post 的请求体用 json or form?

  •  
  •   raiz · Dec 29, 2015 · 3216 views
    This topic created in 3966 days ago, the information mentioned may be changed or developed.
    12 replies  •  2015-12-29 15:48:00 +08:00
    orFish
    orFish
    Dec 29, 2015
    1
    Google 的 api 现在大部分都是用 json
    我们现在也有 json

    有些框架是兼容 post 和 form 的
    maemual
    maemual
    Dec 29, 2015
    2
    json
    matthewgao
    matthewgao
    Dec 29, 2015
    3
    现在应该说都要遵循 REST 标准会比较好一些, REST 标准里并没有强制使用哪种格式来格式化数据,可以是 XML 也可以是 JSON ,或者是其他的,但是普遍建议使用 JSON
    ixiaohei
    ixiaohei
    Dec 29, 2015
    4
    我现在是传文件就用 form ,一般就 json
    usapla
    usapla
    Dec 29, 2015
    5
    我们公司的 web 项目,基本上都是 josn ,感觉使用相当方便,调试也比较清晰。
    felixzhu
    felixzhu
    Dec 29, 2015
    6
    后端通过 request header 统一兼容处理,这样最好

    因为前端的人随时会换,框架也可能会变化, angular 默认就是 json 吧,然后发文件是 form-data ,所以最好不要写死,按照协议来最好
    dapang1221
    dapang1221
    Dec 29, 2015 via Android
    7
    我们这主要是看提交后的动作,能做成无刷新 ajax 而且不提交文件的就 json ,提交完内容跳转到别的页面的索性就就 form 。前端后端约定好了就行了,比较随意
    plantain
    plantain
    Dec 29, 2015
    8
    方便的话(比如 nodejs 的 body-parser ),可以都支持
    lemayi
    lemayi
    Dec 29, 2015
    9
    @alect 123123123
    alect
    alect
    Dec 29, 2015
    10
    @lemayi @我干嘛?
    lemayi
    lemayi
    Dec 29, 2015
    11
    @alect 完全不知道啊。。。
    tonyleen
    tonyleen
    Dec 29, 2015
    12
    JSON
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   797 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 18:58 · PVG 02:58 · LAX 10:58 · JFK 13:58
    ♥ Do have faith in what you're doing.