电子邮件发送失败的http状态代码 [英] http status code for failed email send

查看:164
本文介绍了电子邮件发送失败的http状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个创建用户的API调用.成功后,将创建用户并发送确认电子邮件.响应状态代码为201.

Consider an API call that creates a user. On success, the user is created and a confirmation email is sent. The response status code is 201.

如果未创建用户,则响应状态代码为422.

If the user is not created, the response status code is 422.

如果创建用户但发送确认电子邮件失败,响应状态代码应该是什么?

What should the response status code be if user is created BUT sending the confirmation email failed?

推荐答案

问题的核心在于将RESTful资源创建与RPC样式的操作混合在一起.在REST风格的世界中,用户的创建将是原子操作,并返回201或422(或您选择的任何错误代码).然后,发送确认电子邮件可能是对/api/user/confirmationemailtask的另一个POST,然后分拆了电子邮件过程.当您将两者结合在一起时,就会发现模棱两可的领域.

The core of the problem lies in mixing a RESTful resource creation and an RPC-style action. The creation of the user, in a RESTful world, would be the atomic operation and return 201 or 422 (or whatever error code you choose). Then the sending of the confirmation email might be another POST to /api/user/confirmationemailtask that then spins off the email process. When you combine the two you find the areas of ambiguity.

(动议后人回答的评论)

(moved comment to answer for posterity)

这篇关于电子邮件发送失败的http状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆