Skip to main content

Posts

Showing posts with the label RESTful

Building mock web service in node.js instead of Web API

I needed to build a mock back-end web service this week because the middle-ware team wasn't ready (they're useless standard Java 'enterprise' developers) and @Jason challenged me to write it in node.js . He showed me an example of how this was done before and said it shouldn't take more than 5 minutes to have something up and running, I've done this kind of requirement previously in Web API and thought it would be interesting to finally do 'something' in node. All coding contexts have been changed to protect the innocents :) The requirement was for a web service returning JSON defined resources and the idea was to map the request URL to the local the file system, where the actual content to be returned is contained in a *.json file and the actual file-name represent the HTTP code to be returned, some examples are show below: 'http://localhost:1008/examples/user/1' maps to 'd:\work\node\resources\user\1\200.json' 'htt...

Self hosting a web service inside a test fixture using WebAPI

I have a class which handles all the communication to any back-end RESTful service, it wraps up all the complexity of using HttpWebRequest and provides a simple API: 1: public interface IRestClient 2: { 3: Task<RestResponse<T>> GetAsync<T>(Uri url) where T : class ; 4: Task<RestResponse> PutAsync<T>(Uri url, T resource) where T : class ; 5: Task<RestResponse<T>> PostAsync<T>(Uri url, T resource) where T : class ; 6: Task<RestResponse> DeleteAsync(Uri url); 7: } The implementation of this class isn't relevant for this post - it's all about the behaviour. The behaviour is what I'm trying to test not the internal implementation... So how can I test this in a standard test fixture? I knew it was possible but I didn't think it would so easy... Having used asp.net WebAPI  for hosting services in IIS I knew this was the tech stack I wanted to use, but could...