EzDevInfo.com

response.js

responsive design toolkit Response JS: mobile-first responsive design in HTML5.

Standard JSON API response format? [closed]

Out of curiosity, are there any emerging standards or best-practices when structuring JSON responses from an API? Obviously every application's data is different, so that much I'm not concerned with, but rather the "response boilerplate", if you will. An example of what I mean:

Successful request:

{
  "success": true,
  "payload": {
    /* Application-specific data would go here. */
  }
}

Failed request:

{
  "success": false,
  "payload": {
    /* Application-specific data would go here. */
  },
  "error": {
    "code": 123,
    "message": "An error occurred!"
  }
}

Source: (StackOverflow)

Remove Server Response Header IIS7

Is there any way to remove "Server" response header from IIS7? There are some articles showing that using HttpModules we can achieve the same thing. This will be helpful if we don't have admin right to server. Also I don't want to write ISAPI filter.

I have admin rights to my server. So I don't want to do the above stuff. So, please help me to do the same.


Source: (StackOverflow)

Advertisements

if-modified-since vs if-none-match

What could be the difference between if-modified-since and if-none-match? I have a feeling that if-none-match is used for files whereas if-modified-since is used for pages?


Source: (StackOverflow)

In Rails, how do you functional test a Javascript response format?

If your controller action looks like this:

respond_to do |format|
  format.html { raise 'Unsupported' }
  format.js # index.js.erb
end

and your functional test looks like this:

test "javascript response..." do
  get :index
end

it will execute the HTML branch of the respond_to block.

If you try this:

test "javascript response..." do
  get 'index.js'
end

it executes the view (index.js.erb) withOUT running the controller action!


Source: (StackOverflow)

How to get actual photo from instagram real-time post data?

I subscribed to the #tattoo tag with instagram's real-time api and it's working fine, the problem is that I have no idea how to get the actual uploaded image when the post data looks like this:

[{"changed_aspect": "media", "subscription_id": XXXXXX, "object": "tag", "object_i
d": "tattoo", "time": 1334521880}]

It doesn't give me any info about the media_id or something like that, am I missing something?


Source: (StackOverflow)

What is the point of jQuery ajax accepts attrib? Does it actually do anything?

Spent a solid hour trying to sort out why on earth this (coffeescript)

$.ajax
  accepts: "application/json; charset=utf-8"

did absolutely nothing to change the accepts header, while this

$.ajax
  dataType: "json"

properly sets the accepts header to application/json; charset=utf-8

Totally confused, am I missing something or is the accepts attrib a year-round April Fool's joke?


Source: (StackOverflow)

Is there any way to read cookies from the response object in Java?

It doesn't seem that HttpServletResponse exposes any methods to do this.

Right now, I'm adding a bunch of logging code to a crufty and ill-understood servlet, in an attempt to figure out what exactly it does. I know that it sets a bunch of cookies, but I don't know when, why, or what. It would be nice to just log all the cookies in the HttpServletResponse object at the end of the servlet's execution.

I know that cookies are typically the browser's responsibility, and I remember that there was no way to do this in .NET. Just hoping that Java may be different...

But if this isn't possible -- any other ideas for how to accomplish what I'm trying to do?

Thanks, as always.


Source: (StackOverflow)

BinaryWrite exception "OutputStream is not available when a custom TextWriter is used" in MVC 2 ASP.NET 4

I have a view rendering a stream using the response BinaryWrite method. This all worked fine under ASP.NET 4 using the Beta 2 but throws this exception in the RC release:

"HttpException" , "OutputStream is not available when a custom TextWriter is used."

<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
protected void  Page_Load(object sender, EventArgs e)
{
    if (ViewData["Error"] == null)
    {

        Response.Buffer = true;
        Response.Clear();
        Response.ContentType = ViewData["DocType"] as string;
        Response.AddHeader("content-disposition", ViewData["Disposition"] as string);
        Response.CacheControl = "No-cache";
        MemoryStream stream = ViewData["DocAsStream"] as MemoryStream;
        Response.BinaryWrite(stream.ToArray());
        Response.Flush();
        Response.Close();
    }
}   
</script>


</script>

The view is generated from a client side redirect (jquery replace location call in the previous page using Url.Action helper to render the link of course). This is all in an iframe.

Anyone have an idea why this occurs?


Source: (StackOverflow)

How to return XML in a Zend Framework application

I'm having problems returning XML in my ZF application. My code:

class ProjectsController extends Gid_Controller_Action
{
    public function xmlAction ()
    {
        $content = "<?xml version='1.0'><foo>bar</foo>";
        header('Content-Type: text/xml');
        echo $content;
    }
}

I've also tried the following:

class ProjectsController extends Gid_Controller_Action
{
    public function xmlAction ()
    {
        $content = "<?xml version='1.0'><foo>bar</foo>";
        $this->getResponse()->clearHeaders();
        $this->getResponse()->setheader('Content-Type', 'text/xml');
        $this->getResponse()->setBody($content);
        $this->getResponse()->sendResponse();
    }
}

Could someone point me in the right direction how to achieve this? Thank you very much.


Source: (StackOverflow)

continue processing php after sending http response

My script is called by server. From server i'll receive ID_OF_MESSAGE and TEXT_OF_MESSAGE.

In my script i'll handle incomming text and generate response with params: ANSWER_TO_ID and RESPONSE_MESSAGE.

The problem is that I'm sending response to incomming "ID_OF_MESSAGE", but server which send me message to handle will set his message as delivered to me (it means I can send him response to that ID), after receiving http response 200.

One of solution is to save message to database and make some cron which will be running each minute, but i need to generate response message immidiatelly.

Is there some solution how to send to server http response 200 and than continue executing php script?

thank you a lot


Source: (StackOverflow)

How do I capture a "response end" event in node.js+express?

I'd like to write an express middleware function that sets up a listener on the response's 'end' event, if one exists. The purpose is to do cleanup based on the http response code that the end handler decided to send, e.g. logging the response code and rollback/commit of a db transaction. i.e., I want this cleanup to be transparent to the end caller.

I'd like to do something like the following in express:

The route middleware

function (req, res, next) {
   res.on ('end', function () {
      // log the response code and handle db
      if (res.statusCode < 400) { db.commit() } else { db.rollback() }
   });
   next();
}

The route:

app.post ("/something", function (req, res) { 
    db.doSomething (function () {
       if (some problem) {
          res.send (500);
       } else {
          res.send (200);
       }
    });
 }

When I try this, the 'end' event handler never gets called. The same for res.on('close'), which I read about in another post. Do such events get fired?

The only other way I can think of doing this is wrapping res.end or res.send with my own version in a custom middleware. This is not ideal, because res.end and res.send don't take callbacks, so I can't just wrap them, call the original and then do my thing based on the response code that got set when they call me back (because they won't call me back).

Is there a simple way to do this?


Source: (StackOverflow)

Cause of Servlet's 'Response Already Committed'

What are the common possibilities to encounter this exception in servlet - Response Already committed?


Source: (StackOverflow)

How to customize to_json response in Rails 3

I am using respond_with and everything is hooked up right to get data correctly. I want to customize the returned json, xml and foobar formats in a DRY way, but I cannot figure out how to do so using the limited :only and :include. These are great when the data is simple, but with complex finds, they fall short of what I want.

Lets say I have a post which has_many images

def show
  @post = Post.find params[:id]
  respond_with(@post)
end

I want to include the images with the response so I could do this:

def show
  @post = Post.find params[:id]
  respond_with(@post, :include => :images)
end

but I dont really want to send the entire image object along, just the url. In addition to this, I really want to be able to do something like this as well (pseudocode):

def show
  @post = Post.find params[:id]
  respond_with(@post, :include => { :foo => @posts.each.really_cool_method } )
end

def index
  @post = Post.find params[:id]
  respond_with(@post, :include => { :foo => @post.really_cool_method } )
end

… but all in a DRY way. In older rails projects, I have used XML builders to customize the output, but replicating it across json, xml, html whatever doesnt seem right. I have to imagine that the rails gurus put something in Rails 3 that I am not realizing for this type of behavior. Ideas?


Source: (StackOverflow)

Server response gets cut off half way through

I have a REST API that returns json responses. Sometimes (and what seems to be at completely random), the json response gets cut off half-way through. So the returned json string looks like:

...route_short_name":"135","route_long_name":"Secte // end of response

I'm pretty sure it's not an encoding issue because the cut off point keeps changing position, depending on the json string that's returned. I haven't found a particular response size either for which the cut off happens (I've seen 65kb not get cut off, whereas 40kbs would).

Looking at the response header when the cut off does happen:

{
    "Cache-Control" = "must-revalidate, private, max-age=0";
    Connection = "keep-alive";
    "Content-Type" = "application/json; charset=utf-8";
    Date = "Fri, 11 May 2012 19:58:36 GMT";
    Etag = "\"f36e55529c131f9c043b01e965e5f291\"";
    Server = "nginx/1.0.14";
    "Transfer-Encoding" = Identity;
    "X-Rack-Cache" = miss;
    "X-Runtime" = "0.739158";
    "X-UA-Compatible" = "IE=Edge,chrome=1";
}

Doesn't ring a bell either. Anyone?


Source: (StackOverflow)

What's the minimum lag detectable by a human? [duplicate]

Possible Duplicate:
What is the shortest perceivable application response delay?

I've been profiling some JavaScript UI code because it feels a little laggy. So far, I've found some bottlenecks and optimized them out, but I'd like to define a measurable requirement for this.

How quickly should a response occur in order for a human not to notice lag? For example, what's the minimum detectable delay between when a keyboard key is pressed and when a letter appears on the screen? At what point is further optimization not going to make any difference to a human?

A lot of monitors have a refresh rate at about in the 60-120Hz range. Does that mean the magic number is around 8-16ms?


Source: (StackOverflow)