Skip to main content


Showing posts with the label Web API

Web API Resource URI construction Practices

Main focus of this article would be on how to make Web API more understandable to the consumers from Resource URI construction point. In Web API, each resource will have unique identifier. So, one should be very careful while constructing these URIs. Here are the few very good practices one should go for: URI should belong to NOUN rather than ACTIONS. URI example Is preferred? Remarks api/getemployees × api/employees √ Using GET api/id/employees × api/employees/{id} √ Fetch employee with a given ID using GET api/xyz/xyz/employees × api/employees √ api/employees/orderby/name × api/employees?orderby=name √ Filter criteria Should Nouns be Pluralize or not? It is up to you whether you want to go for pluralize nouns or not. But whatever decision you are making it should be consistent throughout the controller

CRUD operations using ASP.NET Core 2.0 and In-memory database with Entity Framework

In this article, we will create a Web API with in-memory database using Entity Framework and ASP.NET Core 2.0 without any theoretical explanation. To know more on concepts and theory, my previous articles can be referred. Let’s quickly create a new ASP.NET Core application by choosing API template and name it as ConferencePlanner. Add a new Model entity named Workshop inside a newly add Models folder as shown below: public class Workshop {     public int Id { get ; set ; }     public string Name { get ; set ; }     public string Speaker { get ; set ; } } Here we are going to use in-memory class along with EF. So, we have to add a new class for setting up the database context as shown below: public class ApplicationDbContext :DbContext {     public ApplicationDbContext(DbContextOptions<ApplicationDbContext> context): base (context)     {     } } Now we have to maintain multiple workshops under a conference. So, g