Webservice in iOS Swift

Jan 17, 2022 iOS

Types of Webservice in iOS Swift

What is Web Service ?

Webservice in iOS Swift : A web Service is the package  which is used to communicate between the two node(Device) using the network.

There are 2 types of WebService Call

1. SOAP Web Service

2. REST Web Service

REST

REST : It is known as REpresentational State Transfer. It is the Established the resources through the use of the URL to transport the protocols like GET, DELETE, POST,PUT.

It mostly Concern more on the resource. It inherit security measures from the underlying transport protocols. It accept Different format of data like Plain Text,HTML,JSON,XML etc.

Example:

http://{serverAddress}/leadbycode/post

The method used in HTTP Service are

GET  : To read the Data

PUT : to update the exiting Data

POST : To create a new Data

DELETE : To delete the Data

The Standard status code in REST are

404: Data not found

200 : Success

201: Create

401: Unauthorised

500 : Server Error

Advantages of RESTFul web service

  • it is plateform-independent
  • it provide different data format like JSON, text , HTML and XML.
  • they are reusable.
  • they can be written in any programming langauge.

SOAP

SOAP is known as Simple Object Access Protocol. It is XML Based Protocol. Its biggest advantages is the security .Soap is basically used in enterprise application, in legacy code. It uses XML for the network call over HTTP.

Soap Envelop Structure consist of

Header

body (WSDL)

SOAP contains real XML Content  as Request and Response

XML Request

  1. <Envelop xmlns=?http://schemas.xmlsoap.org/soap/envelop/?>  
  2.     <Body>  
  3.         <getCourseDetailRequest xmlns=?http://leadbycode.com/blog?>  
  4.             <id>course1</id>  
  5.         <getCourseDetailRequest>  
  6.     </Body>  
  7. </Envelop>  
 
XML Response
 
  1. <SOAP-ENV:Envelope xmlns:SOAP-ENV=?http://schemas.xmlsoap.org/soap/envelope/?>  
  2.           <SOAP-ENV:Header />             <!?empty header–>  
  3.            <SOAP-ENV:Body>                <!?body begin–>  
  4.                   <ns2: getDetailpostResponse xmlns:ns2=?http://leadbycode.com/post> <!–content of the response–>  
  5.                    <ns2:course>  
  6.                     <ns2:id>blog</ns2:id>  
  7.                     <ns2:name>Coredata<ns2:name>  
  8.                     <ns2:description>swift</ns1:description>  
  9.                     </ns2:psot>  
  10.                     </ns2:getpostResponse>  
  11.                </SOAP-ENV:Body>       <!?body end–>  
  12. </SOAP-ENV:Envelope>  

%3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20value%3D%22%22%20style%3D%22rounded%3D0%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22260%22%20y%3D%22150%22%20width%3D%22190%22%20height%3D%22280%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22%22%20style%3D%22rounded%3D0%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22280%22%20y%3D%22190%22%20width%3D%22150%22%20height%3D%2260%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%224%22%20value%3D%22%22%20style%3D%22rounded%3D0%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22280%22%20y%3D%22270%22%20width%3D%22150%22%20height%3D%22130%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E

Index