Web Services
Web Services
A web service is a program on the internet that answers requests from other programs with data instead of web pages.
A normal website is made for people: it sends back pages to look at. A web service is made for programs: it sends back plain data that another program can use.
Web services allow applications to communicate over the internet through platform-independent and language-neutral standards like XML and HTTP.
How Web Services Communicate
Web services use the same tools as the web:
- HTTP to send requests and answers
- Request methods like GET and POST to say what you want
- Status codes like 200 OK or 404 Not Found to report how it went
- A data format XML or JSON
Why are Web Services Useful?
- Different programs can work together, even if they are written in different languages
- You can reuse work. Many apps can use the same map, payment, or weather service
- They work everywhere. Websites, phone apps, and other servers can all use the same service
A Simple Web Service Example
A weather app on your phone does not measure the weather itself. It asks a weather web service.
The app asks:
GET https://api.weather-example.com/weather?city=Oslo
The web service answers with data (JSON):
{
"city": "Oslo",
"temperature": 8,
"sky": "cloudy"
}
The app then shows that data nicely on your screen.
Web Service or API?
You will often hear the word API too. An API is any way for programs to talk to each other.
A web service is an API that works over the internet. Today, the two words are often used to mean the same thing.