Ads

API Testing -Inbuilt Features

 Web Service:

A service which is available in internet is called web service.API-Application programming interface is interacts between client and server

Client:--

who makes the request(human or piece of software code)

Server--->this gets the request and process it and sending the response

HTTP-->http methods,content types,headers,request ,response,status code,JSON

URL--->uniform resource locator

HTTP Methods: → Get,POST,PUT,DELETE,pATCH,OPtions,TRACE

Content types--->application json or xml

Response--->html or json or xml

status codes-->200,201,304,400,401,402,403,404,500,502,504

 

GET:

  • Idempotent---Never changes

  • used to retrive the informations/resources available

  • not to modify

Post:

  • Used to create new resource

  • not idempotent

Put:

  • Used to update the existing resource

Delete:

  • Used to delete the existing resource

Patch:

  • Used to perform the partial update

1xx series--->just a info

2xx series--->used to retrieve or create resource

3xx series--->for redirectional

4xx series--->client side error

5xx series--->server side error

200-ok

201-created

304-not modified

400-bad request

401-unauthorised

402-payment required

403-forbidden

404--not found

500-internal server error

502-bad gateway

503-service not available

 

 

Native JAVA for Automation:

@Test public void getMEthod(){ URL url=new URL("https://www.hbhsbfs.com."); HTTPUrlConnection connection=(HTTPUrlConnection)url.openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("Content-Type","application/json"); connection.connect(); sysout(connection.getResponseCode()); sysout(connection.getResponseMessage()); InputStream stream=connection.getInputStream() InputStreamReader reader=new inputStreamReader(stream); BufferedReader bufReader=new BufferedReader(reader); String line; while((line=bufReader.readLine())!=null){ sysout(line); } @Test public void postMethod(){ URL url=new URL("https>lm"); HTTPURlConnection connection=(HTTPUrlConnection)url; connection.setRequestMethod("POST"); connection.setRequestProperty("Content-type","application/json"); connection.setDoOutput(true); String json="{"name":"Sangar"} bytes[] byt=json.getBytes(); OutputStream stream=connection.getOutputStream(); stream.write(byt); sysout(connection.getResponsecode()); sysout(connection.getResponseMessage()); InputStream stream=connection.getInputStream(); InputStreamReader reader=new InputStreamReader(); BufferedReader bufReader=new BufferedReader(reader); String line; while((line=bufReader.readLine())!=null){ sysout(line); } } Put similar to Post method Delete similar to get method }

 

 

 

 

Comments

Popular posts from this blog

Rest Assured Api Automation

Appium Notes

Jenkins Notes