Click here to Skip to main content
15,900,591 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a web api serving as a backend for mobile and web application.How i can organize its controllers actions and models.So to make it easy to handle future work.
For example

1-Same controller and different action name for mobile and web for example
api/Customer/GetCustomer_web
api/Customer/GetCustomer_mobile


2-Same controller and same action but different parameter
api/Customer/GetCustomer?app=web
api/Customer/GetCustomer?app=mobile


3-Different Controller
api/Customer_web/GetCustomer
api/Customer_mobile/GetCustomer


4-Something else

Also whats the best practice

What I have tried:

Tried different techniques to implement mentioned in question but need the best practice to do this task.
Posted
Updated 2-Apr-17 11:21am
Comments
Richard Deeming 4-Apr-17 12:08pm    
Why do you need to return different data depending on the caller?
Member 9129971 4-Apr-17 14:00pm    
the more clear word is viewmodel not data, I have different viewmodels for web and mobile for example some fields are shown in web but not shown in mobile , there are different views for both mobile and web , you would say for this i can just create method with some other name, but the problem is the api is built in such a way that if i create other methods then it would be a mess for maintanance , so i need a solution without losing any previous effort.
Richard Deeming 4-Apr-17 14:06pm    
But which fields you do and do not display is a UI concern.

In MVVM terms, the data returned from the API is the model. You use a view-model in the front-end application to adapt that model to the view.
Member 9129971 4-Apr-17 14:51pm    
yes the model for ex:for web we have model A having fields a,b,c,d and for mobile we have same model A having a,b (here c,d are null).
Richard Deeming 4-Apr-17 14:56pm    
No. You have the same model for both. You use the view-model to decide which fields will and will not be shown, and to adapt the model to the view.

You wouldn't have separate database tables for "web customers" and "mobile customers"; so why have separate models for them?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900