What is a web service?
When an app shows the weather, a shop checks a card payment or one system updates another, it is usually calling a web service. A website is built for people to read. A web service is an interface built for programs: it accepts a request in an agreed format and returns data. Many use HTTP and JSON, though the term covers other protocols and formats, and one product can offer both a site and a service.
What happens in one request
A client sends a request to a defined endpoint, which is the address of one operation. The request carries a method, parameters and, where required, credentials. The service validates it, does the work and returns a response. In HTTP APIs the status code gives the broad outcome: success, a problem on the client side such as invalid input, or a failure on the server side. The response body then gives the detail in a documented format.
Why the contract matters more than the code
The contract is the published description of paths, methods, fields, types, authentication, rate limits and error conditions. With it, someone can write a client without ever seeing the server. Versioning follows from this. Changing a field or what it means can break existing applications even when the endpoint address stays the same. Keep backward compatibility where you promised it, and announce a deprecation period before removing anything.
REST, SOAP, GraphQL and webhooks compared
REST is an architectural style and not a single wire format. APIs described as RESTful usually represent resources as URLs and use GET for reading and POST or PUT for changes. A GET should never create a lasting change of state, because clients and intermediaries may repeat or cache it. SOAP uses structured XML messages with formal service descriptions and is still common in enterprise systems.
GraphQL lets the client ask for a chosen selection of fields defined by a schema, often over HTTP. That can cut unnecessary data transfer, at the price of extra complexity around query cost, authorisation and caching. Webhooks turn polling around: instead of asking repeatedly whether something happened, you register an endpoint and the other service calls it when the event occurs. A webhook receiver has to authenticate the sender, cope with retries and guard against the same event being delivered twice. No style is best for every job.
Keeping callers, data and secrets safe
Use HTTPS to protect data in transit, and verify the server certificate. Authenticate callers with a suitable credential scheme, then authorise each operation and each object separately. A valid token proves only what its scope allows. It does not make arbitrary input safe, so validate request sizes and types, keep private data out of error messages and set limits against abuse.
Secrets do not belong in public URLs, client-side source code or logs. If a credential leaks, rotate it. Restrict each credential’s scope and keep production and test credentials apart. If your API accepts a callback URL, validate the destination so that the service cannot be made to send requests into internal networks. Document which personal data is returned, and retain only what you need.
Timeouts, retries and duplicate requests
Networks fail, so a client needs timeouts, a bounded number of retries and clear handling of partial failure. Repeating a read is safe. Repeating a payment or any other change is not, unless the service is designed to be idempotent, meaning a repeated request has the same effect as a single one. A common design is a unique key sent with the request so that the server can recognise the repeat. Pagination keeps large result sets manageable. Caching reduces load for stable public data, while private or fast-changing responses need a careful cache policy.
How to tell whether a service is healthy
Measure latency, error rate and availability from the path real clients use. A server can return HTTP 200 and still send incomplete or unusable data, so monitor the expected business outcome too. Rate limits protect the service, but clients need them communicated predictably. If users depend on the service, give them a status page or a support channel for incidents.
Before you build one or depend on someone else’s
Start from the user’s task and the data contract. Then pick an interface style that clients can implement and your team can maintain. Test normal responses, malformed input, expired credentials, permissions, pagination and timeouts. Keep the examples current and show concrete errors. When you integrate a third-party service, read its usage limits, data policy and change notices. However convenient the endpoint, it is a dependency that can fail.