What is web services?

Overview

Web services are standardized ways for applications to communicate over the internet. They expose functionality or data from one system so other systems can request and consume it programmatically. Web services enable interoperability between heterogeneous systems and are fundamental to modern distributed architectures, APIs, and integrations.

Key Characteristics

Web services typically:

  • Use common web protocols (HTTP/HTTPS)
  • Exchange data in standard formats (JSON, XML)
  • Provide well-defined interfaces (endpoints and methods)
  • Support stateless request/response interactions
  • Include discovery and documentation (e.g., WSDL, OpenAPI)

Main Types of Web Services

There are two dominant styles:

SOAP (Simple Object Access Protocol)

SOAP is a protocol that uses XML-based messages and a WSDL (Web Services Description Language) to describe service contracts. It supports advanced features like built-in error handling, WS-Security, transactions, and reliable messaging—common in enterprise scenarios.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetCustomer xmlns="http://example.com/customer">
<CustomerId>123</CustomerId>
</GetCustomer>
</soap:Body>
</soap:Envelope>

REST (Representational State Transfer)

REST is an architectural style that uses standard HTTP verbs (GET, POST, PUT, DELETE) and lightweight formats such as JSON. RESTful APIs are simple, scalable, and widely used for web and mobile applications.

GET /api/customers/123 HTTP/1.1
Host: api.example.com
Accept: application/json

Response:
{
"id": 123,
"name": "Acme Corp",
"email": "[email protected]"
}

SOAP vs REST — Quick Comparison

  • Message format: SOAP uses XML; REST commonly uses JSON (or XML).
  • Style: SOAP is protocol-centric; REST is resource-centric.
  • Complexity: SOAP is heavier with built-in standards; REST is lightweight and easier to adopt.
  • Use cases: SOAP for enterprise-level transactional needs; REST for web/mobile APIs and microservices.

Common Concepts

Authentication and security (OAuth, API keys, TLS), rate limiting, versioning, and documentation (OpenAPI/Swagger) are essential when designing production-ready web services.

Web Services in Salesforce Context

Salesforce supports both SOAP and REST web services. You can:

  • Expose Apex classes as REST endpoints using @RestResource and @Http* annotations.
  • Expose SOAP endpoints via Apex web services using the webservice keyword and WSDL generation.
  • Consume external web services using HTTP callouts (HTTP, HttpRequest, HttpResponse) or by configuring external services and named credentials.

Conclusion

Web services are the backbone of system-to-system communication on the web. Choosing between SOAP and REST depends on requirements like security, transaction support, and client compatibility. Understanding web services is essential for integrating platforms such as Salesforce with external systems.