douji5329 2015-02-04 15:01
浏览 49

REST API - 从一个控制器中的其他端点保存数据

I have two API endpoints, Person and Domain. Each of them has an own controller, used to handle GET/POST/PUT/DELETE requests.

Now, a domain has to be assigned to a person, so what I thought was the following. When adding a Person the user can send JSON to the REST API containing an URL which will be saved as a new Domain.

This is just a simple example. In the real life example, I have many other endpoints like FacebookAccount, LinkedInAccount, GooglePlusAccount etc.

My main question is: Is it a good practice, to allow the API user to add data to multiple Endpoints/Ressources in one request? Because, what I see as a problem is the following:

I don't want the user to do 10 requests to add a person with all his data like his domains, Facebook accounts etc. if he has multiple.

  • 写回答

1条回答 默认 最新

  • dongrenshi0889 2015-02-04 15:19
    关注

    There's no need to do two requests if you can do it in one. It would be like doing two car trips to drop two things off at the same place, when you could have just taken both of them in the car with you at once.

    Just add the {domain_id} to your POST data when you call POST /persons

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?