1

I have a controller to send send a message from my site:

example.com/contact/send-message

Ok here, but in my API I've created the same method:

api.example.com/contact/send-message

in the API should I keep the same method and just call the method inside the controller? When should I use controller methods or api methods?

KingCrunch
  • 128,817
  • 21
  • 151
  • 173
Leabdalla
  • 656
  • 9
  • 19

1 Answers1

2

By all means, separate your API logic from your web application logic. One will be used via a web browser, and the other one will just interface with other software. Each of them solves different problems.

Use a fat model, thin-controller approach. Meaning that all the data processing methods should be placed in your model, not in the controller. From there, you can call those methods either from your API controller, or from your web controller.

An excellent plugin to build a restful API is Phil Sturgeon's REST Server

Samer Bechara
  • 2,099
  • 16
  • 24