Reputation: 811
I have created REST apis to manage a resource (with endpoint say /user/resource
). I can query the resource making a GET call and create the resource using the POST call. I use the api to manage resources from UI by making ajax calls to the REST api endpoint.
Now there is a requirement to send an email upon creating resource, and if the resource is already existing then sending a mail with the resource details in the mail (without modifying the resource) . I am confused if sending mail should be part of the the original REST api used for creating the resource or sending the mail should be handled separately . If "sending the mail" isn't part of the original REST api then it would involve some more handling on my UI for making another call to send a mail. Also if i expose "sending the mail" logic by means of another REST api then how should the endpoint be structured , will it be something like /user/resource/email
since the mail sending is only related to the resource or should it be /user/email
Upvotes: 0
Views: 225
Reputation: 186
Your question is not very clear. However, you can try to send mail in same api where you are performing business operation.
For example:
public Object createResource() {
//Perform your business operation here
//check if your resource is already exists or not. Depending on the result call
Object sendEail(..,..,..);
}
private Object sendEail(String address,String subject,String body) {
//Write code for sending mail here
}
I hope you understand my point.
Upvotes: 1