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?

6
  • 1
    What are you asking? I'm not sure I understand. How does this API relate to your real site? Commented Feb 12, 2013 at 21:52
  • 1
    My question is about MVC and REST conflict. Should I keep the send_message() in the controller and call it from the API, or should I duplicate function in the API? Commented Feb 12, 2013 at 22:00
  • In my site I can call the controller or call the API. What is better? Commented Feb 12, 2013 at 22:01
  • I've found similar answer: stackoverflow.com/questions/10346342/… Commented Feb 12, 2013 at 22:12
  • The dillema: use MVC Controllers or WebAPI? Commented Feb 12, 2013 at 22:12

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Fat-model, thin controller. Got it! Thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.