[Practical collection of WEB APIs]-Introduction to WEB APIs (1)
As the first article of this series, this article provides a basic introduction. experienced people can jump to the second part to create ProductController.
Create a Web API Project
Here we use VS2013 and. NET 4.5.1 to create a Web API 2 project.
[RoutePrefix ("api/products")] public class ProductController: ApiController {[HttpGet, Route ("product/getList")] public Page <Product> GetProductList () {throw new NotImplementedException ();} [HttpGet, Route ("product/get")] public Product GetProduct (Guid productId) {throw new NotImplementedException ();} [HttpPost, route ("product/add")] public Guid AddProduct (Product product) {throw new NotImplementedException ();} [HttpPost, Route ("product/update")] public void UpdateProduct (Guid productId, Product product) {throw new NotImplementedException ();} [HttpDelete, Route ("product/delete")] public void DeleteProduct (Guid productId) {throw new NotImplementedException ();}}
Start the program after adding it. The result is as follows:
OK. Now you can add your own backend business logic to complete the operations at the business layer.
Code in this chapter: Download the code