Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to design REST API for email sending service?

Tags:

rest

How to design REST API for email sending service by using POST, GET, PUT, DELETE?

send: POST - /email
retrieve: GET - /email/{id}
delete: DELETE - /email/{id}

Is it the correct way of designing REST API? I feel like it's not intuitive to map POST to the action "send".

like image 322
janetsmith Avatar asked Sep 07 '12 01:09

janetsmith


People also ask

Can an API send an email?

An email API allows applications to access functions offered by the email service provider's platform, including generating and sending transactional emails, manipulating templates, moving or editing folders, building drafts, and more.


1 Answers

The scheme you have given is correct. Alternatively you can use controllers to perform some more complex actions.

In your case it can look like this:

(action)           (verb)   (URI)                             (type)
create:            POST   - /emails                         - collection
retrieve:          GET    - /email/{id}                     - resource
update:            PUT    - /email/{id}                     - resource
delete:            DELETE - /email/{id}                     - resource
send immediately:  POST   - /email/{id}/sendImmediately     - controller
just send:         POST   - /email/{id}/send                - controller
do something else: POST   - /email/{id}/someOtherActionType - controller

Note new controllers and the change creation works. The latter is rather subjective, but reasonable (as you cannot really access the URL of "no actual email" like I would interpret "/email" without "{id}" part).

Additional resources:

  • REST API Design Rulebook
like image 93
Tadeck Avatar answered Oct 21 '22 02:10

Tadeck