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?
As @Dai explained the zest and I completely agree with him. In addition, I would like to provide you some real-life difference besides.
Web Service:
As Web Service
basically, used WSDL
which used to communicate with SOAP
or XML
base service. However, the main challenge in Web Service
was to handle cross-platform request. We used to add service reference as following way: While developped Web Services.
Web API:
Considering these drawbacks, Microsoft, later 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 as robust as Web API
nowadays. 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, is lightweight while writing any new method. Where web service
leads to some demerits to the developer.