| |
browse.develop.com
Browse.develop.com is a community that was established to collect and
organize valuable web information. Our technical staff have selected and
indexed information and courses that they feel will help you stay
current on best practices across the SDLC.
|
5 Articles match "Books","Restful"
| Related DevelopMentor Courses | MORE | | Using SignalR for real time data updates To be fair the JavaScript would be using jQuery in most cases and would be quite trivial to write against some REST service. Replacing a REST service with SignalR Suppose the client doesn’t load the data using a REST service but uses SignalR instead. In the following code the clients starts the communications hub and passed the loadBooks callback to load the books as soon as the communications are initialized. $( function () {. then( function (books) {. each(books, function () {. var books = _repo.GetBooks(); return books; }. }. Enjoy! The Problem Solver - Wednesday, July 25, 2012 Unit testing a ASP.NET WebAPI controller 'One of he goals of the ASP.NET WebAPI is to make REST style API controllers more testable than more traditional WCF services where in the past. Testing a simple ApiController that gets data Suppose we have the following ASP.NET WebAPI Controller with two Get methods, the first returns the complete list of books and the second returns the book with the requested ID. 14: 15: // GET api/books. 24: var book = _repo.GetBook(id); 25: 26: if (book == null ). 30: 31: return Request.CreateResponse(HttpStatusCode.OK, book); 32: }. ASP.NET REST WebAPI The Problem Solver - Sunday, May 12, 2013 Unit testing code depending on the ASP.NET #WebApi HttpClient But with a REST service there is both a client and a service component. In this case the client application contains the following class to load books from the REST WebAPI controller: 1: public class BooksClient. 19: 20: public Book GetBook( int id). 27: 28: public Tuple PostBook(Book book). 30: var response = _httpClient.PostAsJsonAsync(BaseUrl.ToString(), book).Result; This class uses the HttpClient to request the data from the service and extracts the books from the body before returning them. 5: var books = new []. 14: {. 21: {. The Problem Solver - Monday, May 20, 2013 |
40 Articles match "Books","Restful"
| The Latest from DevelopMentor | MORE | | Integrating the #WebAPI HttpClient and ApiController in a single test Testing the getting of books The code used to test getting the books from the ApiController is actually quite similar to testing just the client code. In this case it uses an in memory repository so I know exactly that the same set of 5 books are returned every time. 11: var books = client.GetBooks(); 12: 13: // Assert. The test of adding a new book. Adding a new book in an integration test is just as simple: 1: [TestMethod]. 13: var response = client.PostBook(book); 14: 15: // Assert. 17: client.PutBook(book); 18: 19: // Assert. Maurice de Bejeir - Monday, May 27, 2013 Unit testing code depending on the ASP.NET WebApi HttpClient But with a REST service there is both a client and a service component. In this case the client application contains the following class to load books from the REST WebAPI controller: 1: public class BooksClient. 19: 20: public Book GetBook( int id). 27: 28: public Tuple PostBook(Book book). 30: var response = _httpClient.PostAsJsonAsync(BaseUrl.ToString(), book).Result; This class uses the HttpClient to request the data from the service and extracts the books from the body before returning them. 5: var books = new []. 14: {. 21: {. Maurice de Bejeir - Monday, May 20, 2013 Unit testing code depending on the ASP.NET #WebApi HttpClient But with a REST service there is both a client and a service component. In this case the client application contains the following class to load books from the REST WebAPI controller: 1: public class BooksClient. 19: 20: public Book GetBook( int id). 27: 28: public Tuple PostBook(Book book). 30: var response = _httpClient.PostAsJsonAsync(BaseUrl.ToString(), book).Result; This class uses the HttpClient to request the data from the service and extracts the books from the body before returning them. 5: var books = new []. 14: {. 21: {. The Problem Solver - Monday, May 20, 2013 | -
| The Best from DevelopMentor | MORE | - Using HTTP status codes in a REST service
When we are building REST service we embrace HTTP and as a result we also embrace all the HTTP status codes, not just 200 and 500. Book GetBook( int id). {. If I request the books resource using the URL [link] I get the following. However if I use the URL [link] to get a book with id 999 which doesn’t exist I see the following: Not exactly what I want, there is no book found and yet it returns a null book resource. HttpResponseMessage result; var book = _repo.GetBook(id); if (book != result = new HttpResponseMessage (book); }. The Problem Solver - Wednesday, July 20, 2011 - Using SignalR for real time data updates
To be fair the JavaScript would be using jQuery in most cases and would be quite trivial to write against some REST service. Replacing a REST service with SignalR Suppose the client doesn’t load the data using a REST service but uses SignalR instead. In the following code the clients starts the communications hub and passed the loadBooks callback to load the books as soon as the communications are initialized. $( function () {. then( function (books) {. each(books, function () {. var books = _repo.GetBooks(); return books; }. }. Enjoy! The Problem Solver - Wednesday, July 25, 2012 - Using the WCF Web API in an ASP.NET MVC application
Now that works but it is far more likely that you will want to be using IIS and host the REST service as part of a web application. So in this blog post I am going to show how to do the normal thing I Created an ASP.NET MVC 3 app to host the REST service. All we can do is retrieve a list of books or get an individual one. Book GetBook( int id). {. non browser client application can consume this REST service quite easily using a standard HTTP API available. www.dotnetevents.nl.NET WCF ASP.NET VS2010 Futures NuGet RESTrepo = repo; }. List GetBooks(). {. The Problem Solver - Monday, June 13, 2011 - Using HTTP methods in a REST service
In that case wee need to let the website know what books we want to order. When REST came along and it embraced the HTTP standard is also embraced the HTTP verbs. And it turns out that makes perfect sense because REST is about resources. Be careful though, sending an update setting the number of books orders to 2 is an idempotent action but adding 1 to the current amount on order isn’t. Repeating the first action would still result in 2 books being ordered but repeating the second would result in 3 books being ordered. And that makes perfect sense. The Problem Solver - Thursday, August 25, 2011 - Unit testing a ASP.NET WebAPI controller
'One of he goals of the ASP.NET WebAPI is to make REST style API controllers more testable than more traditional WCF services where in the past. Testing a simple ApiController that gets data Suppose we have the following ASP.NET WebAPI Controller with two Get methods, the first returns the complete list of books and the second returns the book with the requested ID. 14: 15: // GET api/books. 24: var book = _repo.GetBook(id); 25: 26: if (book == null ). 30: 31: return Request.CreateResponse(HttpStatusCode.OK, book); 32: }. ASP.NET REST WebAPI The Problem Solver - Sunday, May 12, 2013 - REST services and URL’s
When designing and building REST services the URL’s used take on a rather important part. So for example: [link] Points to a specific book identified by 123 (whatever that might mean). link] Points to the collection of books. link] Points to a collection of books authored by Douglas Adams. For example: [link] This would search the book collection for books about robots. www.dotnetevents.nl.NET WCF REST dotnetmagSo it pays to think a lot about the URL structure up front. Basically a URL is used to identity a recourse. Enjoy! www.TheProblemSolver.nl The Problem Solver - Thursday, July 14, 2011 - How to get started with Knockout.js
Once you get into doing more client side JavaScript code with business applications and REST services you are going to run into the question of how to construct the client side HTML required to show the data to the users. then( function (books) {. $.each(books, each(books, function () {. $( " " ).text( then( function (books) {. var html = tmpl( "books_tmpl" , { books: books }); $( "#books" ).html(html); var book = books[i];%> by. REST dotnetmag HTML5 Knockout jQueryclick( function () {. $.getJSON( The Problem Solver - Monday, February 6, 2012 %>
| | |