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 6705235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:22:49+00:00 2026-05-26T07:22:49+00:00

I am creating a REST API and I have been playing with the idea

  • 0

I am creating a REST API and I have been playing with the idea of allowing bundling of requests from clients. By bundling I mean they can send one request, containing multiple “real” requests, and they get delivered to the client together. Typically javascript ajax requests. Something like this:

POST /bundlerequest

["/person/3243", "/person/3243/friends", "/comments/3243?pagesize=10&page=1", "/products", "/product/categories" ] 

(The bundled request can only be GET requests, as of now at least)
This is intended to return something like this

{
    "success" : ["/person/3243", "/person/3243/friends", "/comments/3243?pagesize=10&page=1", "/products", "/product/categories" ],
    "error" : [],
    "completiontime" : 94,
    other relevant metadata...
    "responses" : [
        {"key" : "/person/3243" , "data" : {"name" : "John", ...} },
        {"key" : "/person/3243/friends" , "data" : [{"name": "Peter", "commonfriends" : 5, ...}] },
        etc...
    ]
}

The benefits of this bundling is that it reduces the number of requests and that is especially important on mobile devices for instance.

So my first question is, is my approach to this a good one? Does anyone have experience with doing something like this?

AFAIK the common way of solving this is to write server side code to return combined data, that I believe is relevant for the client(s). (The twitter user stream for instance does this, combining person info, latest tweets, latest personal messages etc.) But this makes the API very opinionated and when the client needs changes the server might need to change to accomodate to optimize.

And the second question is how to implement this?

My backend is ASP.NET MVC 3 and IIS 7. Should I implement it in the application, having an bundlerequest action that internally calls the other actions specified in the request?

Could it be implemented in IIS 7 directly? Writing a module that transparently intercepts requests to /bundlerequest and then calls all the corresponding sub requests, making the application totally unaware of the bundling that happens? This would also allow me to implement this in an application-agnostic way.

  • 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-26T07:22:49+00:00Added an answer on May 26, 2026 at 7:22 am

    You could use an asynchronous controller to aggregate those requests on the server. Let’s first start by defining a view model that will be returned by the controller:

    public class BundleRequest
    {
        public string[] Urls { get; set; }
    }
    
    public class BundleResponse
    {
        public IList<string> Success { get; set; }
        public IList<string> Error { get; set; }
        public IList<Response> Responses { get; set; }
    }
    
    public class Response
    {
        public string Key { get; set; }
        public object Data { get; set; }
    }
    

    then the controller:

    public class BundleController : AsyncController
    {
        public void IndexAsync(BundleRequest request)
        {
            AsyncManager.OutstandingOperations.Increment();
            var tasks = request.Urls.Select(url =>
            {
                var r = WebRequest.Create(url);
                return Task.Factory.FromAsync<WebResponse>(r.BeginGetResponse, r.EndGetResponse, url);
            }).ToArray();
    
            Task.Factory.ContinueWhenAll(tasks, completedTasks =>
            {
                var bundleResponse = new BundleResponse
                {
                    Success = new List<string>(),
                    Error = new List<string>(),
                    Responses = new List<Response>()
                };
                foreach (var task in completedTasks)
                {
                    var url = task.AsyncState as string;
                    if (task.Exception == null)
                    {
                        using (var response = task.Result)
                        using (var stream = response.GetResponseStream())
                        using (var reader = new StreamReader(stream))
                        {
                            bundleResponse.Success.Add(url);
                            bundleResponse.Responses.Add(new Response
                            {
                                Key = url,
                                Data = new JavaScriptSerializer().DeserializeObject(reader.ReadToEnd())
                            });
                        }
                    }
                    else
                    {
                        bundleResponse.Error.Add(url);
                    }
                }
                AsyncManager.Parameters["response"] = bundleResponse;
                AsyncManager.OutstandingOperations.Decrement();
            });
        }
    
        public ActionResult IndexCompleted(BundleResponse response)
        {
            return Json(response, JsonRequestBehavior.AllowGet);
        }
    }
    

    and now we can invoke it:

    var urls = [ 
        '@Url.Action("index", "person", new { id = 3243 }, Request.Url.Scheme, Request.Url.Host)', 
        '@Url.Action("friends", "person", new { id = 3243 }, Request.Url.Scheme, Request.Url.Host)', 
        '@Url.Action("index", "comments", new { id = 3243, pagesize = 10, page = 1 }, Request.Url.Scheme, Request.Url.Host)',
        '@Url.Action("index", "products", null, Request.Url.Scheme, Request.Url.Host)', 
        '@Url.Action("categories", "product", null, Request.Url.Scheme, Request.Url.Host)' 
    ];
    $.ajax({
        url: '@Url.Action("Index", "Bundle")',
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(urls),
        success: function(bundleResponse) {
            // TODO: do something with the response
        }
    });
    

    Of course some tweaking might be necessary to adapt this to your specific needs. For example you mentioned sending AJAX requests with session expired which might redirect to the Logon page and thus not capturing the error. That’s indeed a PITA in ASP.NET. Phil Haack blogged a possible way to circumvent this undesired behavior in a RESTful manner. You just need to add a custom header to the requests.

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

Sidebar

Related Questions

I'm creating a JSON REST API (lots of caps there), and already have Data.Aeson.Generic
I have been struggling with choosing a methodology for creating a RESTful API with
Since I can't find a chuffing job, I've been reading up on ReST and
I am creating a REST API in ASP.NET MVC. I want the format of
We are trying to implement a REST API for an application we have now.
a while ago, i asked about how to implement a REST api. i have
We are creating an API that suits the benefits of a REST based architecture.
I am in need of creating a rest api for syncing data with my
I have been looking into creating a signature on the OAuth site & over
I am creating a Windows 7 mobile Silverlight project. I use Rest api for

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.