API Design: Expose XML or Objects # 2

I recently asked this question: Expose XML or Objects - thanks everyone for the answers.

One moment to clarify.

  • The API will always be accessible remotely (i.e. as a service), most likely through webservices or WCF.

I agree that a theoretically tightly typed API representing objects as inputs / outputs is the right way. However, I feel that there is still an argument for publishing XML. As I see it, the reasons for using XML are:

  • Business rules can be written by Schematron business analysts.
  • The interface is weakly typed, but as soon as it is called, the data can be verified based on data and business rules.
  • The implementation of the service will be easier. There is no need to create a domain object model.
  • An XML schema has already been defined (we have a schema data dictionary).
  • Using web services technology means that the XML-based API does not need to be changed when new types of vehicles are added.

    void AddNewCar( string newCarXml )    
    string[] GetCars( /* some query conditions */ )
    

    If we used an object-based API, then to add a new type we will need a new request method that defines possible derived types that can be returned (see the extension of the service website ). Updating a web service like this will require these services and all existing clients to be rebuilt and redistributed.

API, ? . , XML (XML ). API, ? , - .

, ? , , .

+2
6
  • ( ).
  • .
  • - .
  • - , .
  • .
  • .Net Xml , , , xml.
+2

XML ( , XML), :

  • XML XSD , . , .

  • , -, .

    /li >
  • , , .

, , ... :

  • .
  • .
  • , , (?).
  • - , .
+1

XML, XML. , PITA .

API- -, wsdl/xsd . , , , .

- Object ↔ XML ( ), SOAP . :

void addCar(Car newCar);
Car getCar(String make, String model, String year);
void removeCar(...);
List<Car> getAllCars();

. wsdl Java, #, PHP, Python ..

:

int addCarXML(String carXML);
String getCarXML(int carID);

webservice cruft - wsdl, xsds XML...

+1

, (, , int ..). , , , (, ) .

, Xml -, , . .

, , , , . ( ), "" , , ? XML ( , ).

API-, , , , XML- , . - API , API XML, . .

+1

Contract-First Design, - Spring . - XML- . XML . , , XML.

, . , . , , , , , ..

+1

- ; -p, . - ( ".proto" ), - , , . , , (protobuf-net) .

, - , . (protobuf-net) WCF RPC; -p

+1

Source: https://habr.com/ru/post/1703070/


All Articles