3

Currently I am using Axis2 to make some REST API. And I am confused about the difference between a SOAP style url and a REST style url. Can anyone explain this?

For example, for an server API written in java like this:

package cn.edu.xidian;

public class Salary {
    public int getSalary(String name) {
        if ( name.equals("zhangsan") ) {
            return 3000;
        } else if ( name.equals("lisi") ) {
            return 4000;
        } else 
            return 5000;
    }
}

The REST url for GET this service will look like:

http://localhost:8080/axis2/services/SalaryService/getSalary?name=zhangsan

If my comprehension is right, this url goes into the server side API, call the method 'getSalary' with an argument 'name' equals 'zhangsan', and then the RESTful output in the browser will look like:

<ns:getSalaryResponse>
    <ns:return>3000</ns:return>
</ns:getSalaryResponse>

Then what will a SOAP style URL and related stuff look like?

1

1 Answer 1

4

A URL in itself is not SOAP or REST, it's a URL. (are the adjectives SOAPy and RESTful?)

First, the example of your REST resource:

  http://localhost:8080/axis2/services/SalaryService/getSalary?name=zhangsan

looks you're building some type RPC over HTTP, like your trying to use quasi-REST structure to implement a remote function calls. Many would not consider this good REST.

SOAP is an XML encoded messaging system implemented over some transport layer.

SOAP is not limited to HTTP for transport while REST is by it's nature. The fact you can HTTP for transport for SOAP via URLs and structure those URLs however you want is inconsequential. Also, the fact that most SOAP APIs are probably mostly implemented across HTTP in reality is also irrelevant.

REST is a concept of using the HTTP verbs (PUT, GET, POST, etc...) and response codes as they are intended as the protocol to access and control resources. This includes for creation, modification, deletion, etc... of those resources.

The structure of a SOAP url might in fact look exactly like a REST api, but with REST, the structure should strongly reflect the logical structure of the resource. You don't have to to be fully RESTful, but if not your REST API wouldn't be developer friendly. SOAP isn't necessarily required to have nice urls that reflect data structure as you can provide a WSDL which outlines and can describe the soap services available with just about any URL structure you use. In fact, I've seen quite a few totally acceptable SOAP services that had urls to that seem to be arbitrarily dropped in over the course of time, not reflecting any type of structure.

Sign up to request clarification or add additional context in comments.

2 Comments

can you give me an example of an soap url?
Any URL can be a 'SOAP' or 'REST' URL. The URL is just the location. With REST it's a resource while SOAP is transporting messages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.