Home > OS >  Web service vs Web API (What's the real difference)
Web service vs Web API (What's the real difference)

Time:10-08

Can someone explain me the difference between Web services & web API? I have gone through so many blogs but all of them seems to be using the same bookish knowledge. What's the actual difference between them in real terms?

CodePudding user response:

As enter image description here

enter image description here

Web API:

Considering these drawbacks, Microsoft, latter on developed the Web API more specifically, Asp.net Web API which provide the robust functionality for cross platform development using REST pattern mostly used Json data. It doesn’t mean that web service cannot do that, but not robust as Web API now a days. Unlike, web service we don’t need to go through any integration hassle as above which we can directly develop using asp.net core project and can open the route to call from anywhere.For instance below example:

    [ApiController]
    [Route("api/VehicleFilter")]
    public class VehicleFilterController : ControllerBase
    {

        private readonly ApplicationDbContext _context;
        private readonly IWebHostEnvironment _environment;


        public VehicleFilterController(IWebHostEnvironment environment, ApplicationDbContext context)
        {
            _environment = environment;
            _context = context;
        }
       
        [HttpGet]
        public async Task<IActionResult> GetAllFilter()
        {

           string VehicleName = "Hatchback";
           var sqlCommand = $"EXEC GetVehicleByTile {VehicleName}";
           var vehicleFilterValues = await _context.VehicleFilter.FromSqlRaw(sqlCommand).ToListAsync();
           return Ok(vehicleFilterValues);
        }


    }

To summarize, Web API provides more flexibility and robustness and of course its lightweight while writing any new method. Where web service leads to some demerits to the developer.

  • Related