J86
J86

Reputation: 15237

How to delay the response of my Web API

I am working on a Web API project and that has an Artist Web API Controller. On there, there is the api/artist method that is a GET for all artists.

When making the call to this method, I would like a 3 second delay before I serve the data, how can I achieve this?

CODE

public class ArtistController : ApiController
{
    private GlContext db = new GlContext();

    // GET api/Artist
    public IQueryable<Artist> GetArtists()
    {
        return db.Artists;
    }
}

I know that you wouldn't want to do this in a production environment, but I am playing with preloaders, and in order to test them properly I need to introduce this delay.

Upvotes: 2

Views: 5237

Answers (1)

Andrew Cox
Andrew Cox

Reputation: 10988

If it is just for testing you can always go for Thread.Sleep(3000)

http://msdn.microsoft.com/en-us/library/d00bd51t%28v=vs.110%29.aspx

Upvotes: 2

Related Questions