Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3663546
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:32:33+00:00 2026-05-19T01:32:33+00:00

I am programming an API that would be used by both a web app

  • 0

I am programming an API that would be used by both a web app and a mobile app and I am using ASP.NET MVC 2 in my technology stack.

Currently, I have an Rest-like API service which returns data in JSON format.
This works well for the mobile app, but I also want to make it work for the web app as well.

Would having the controller action return either a HTML View or JsonResult be a good approach for this?

The only difference between the web app and the mobile app is the view layer; the app logic is the same.

I guess I could create a controller that is used for the web app, but I think the a lot of logic would be duplicated from the API controller.

Edit

I do have another layer that handles all the app logic, but the API controller still has some logic to validate the parameters and error handling when it returns the JSON response. The duplicate logic so far would be the validation part.

Here is some code snippets:

public JsonResult GetList(string accessToken, string listId)
 {
    if (string.IsNullOrEmpty(accessToken))
        return Json(new { success = false, exceptionMessage = "Facebook access token is required." });
    if (string.IsNullOrEmpty(listId))
        return Json(new { success = false, exceptionMessage = "The list id is required." });

    string facebookId = null;
    var facebookIdParseSuccess = GetFacebookId(accessToken, out facebookId);

    if (!facebookIdParseSuccess)
        return Json(new { success = false, exceptionMessage = "There was a problem accessing your Facebook profile information." });

    try
    {
        _groceryListManager.FacebookId = facebookId;
        var groceryList = _groceryListManager.GetList(listId);
        GroceryListViewModel mappedList = new GroceryListViewModel();
        Mapper.Map(groceryList, mappedList);
        return Json(new { success = true, results = mappedList });

    }
    catch (Exception ex)
    {
        return Json(new { success = false, exceptionMessage = "..."});
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:32:34+00:00Added an answer on May 19, 2026 at 1:32 am

    I’ve seen one action method return both before, but, in my opinion, you are better off having two separate action methods. You can have them both call off to another method with the shared code, but since they are used for two very different things, you might find it is easier to maintain if you have two methods (a future requirement might cause one to change in a way that makes it difficult to support both in a single method).

    Whether they are in the same controller or not is really more dependent on the nature, size, and complexity of the application. I have separated the API as a completely different project from the HTML. I have shared dlls for accessing the data and other common functions, but the MVC projects are different.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to programming with the Win32 API, and I'm still getting used to
Programming languages had several (r)evolutionary steps in their history. Some people argue that model-driven
Looking at examples about socket programming, we can see that some people use AF_INET
I started a new job in a company that loves using the word, enterprise.
I am new to iPhone programming and would like to be able to use
Programming Student here...trying to work on a project but I'm stuck. The project is
Programming in vim I often go search for something, yank it, then go back
Programming PHP in Eclipse PDT is predominately a joy: code completion, templates, method jumping,
Programming is learned by writing programs. But code reading is said to be another
Some programming languages such as Java and C# include encryption packages in their standard

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.