REST API TESTING

In this documentation, I want to note how to test REST API using this two method :

  1. Using SoapUI
  2. Using CuRL from command line/linux-like

The Method I documented here is only for GET, and POST only. Well other method is similar, you can read it from the source I read before.

Using SoapUI

– GET –

rest_request_editor_os

– POST –

Basically for POST you need to put the parameter in the payload (body request)

Using CuRL (command line)

What is curl?

Well, curl is a command line tool and library for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet and TFTP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, HTTP/2, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, Kerberos…), file transfer resume, proxy tunneling and more.[1]

– GET –

curl http://localhost:8888/aplikasi/getApi/1

curl http://localhost:8888/aplikasi/getApi/encodedurl?a=abc&b=123

– POST –

(using url-encoded)

curl -i -X POST -H “Content-Type:application/x-www-form-urlencoded” http://api.aplikasi.co.id/postApi -d ‘a=abc&b=123&username=johndoe’

(using json)

curl -i -X POST -H “Content-Type:application/json” http://api.aplikasi.co.id/postApi -d ‘{“a”:”abc”,”b”:”123″,”username”:”johndoe”}’

(using multiple header)

curl -i -X POST -H “Content-Type:application/x-www-form-urlencoded” H “Accept-encoding:gzip” http://api.aplikasi.co.id/getApi -d ‘a=abc&b=123&username=johndoe’

– CuRL Options –

  • -H, --header – customer header to pass to the server
  • -i, --include – include protocol headers in the output (H/F)
  • -X, --request – specify request  COMMAND (GET, PUT, DELETE…)  to use
  • -v, --verbose – make the operation more talkative
  • -c,  – is to save the cookies on the cookies.txt file. And since we are doing a login this is important
  • -d,  – allows you to set the request body, which you will be using on drupal services to send the parameters

4 pemikiran pada “REST API TESTING

    • dalam kasus ini kebutuhannya mengecek apakah dari satu mesin bisa mengehit api REST di server. ada potensi blocking network saat itu. Maka dari itu linux based command yg kudokumentasikan

  1. Trus kalo butuh yg agak advanced, ngecek performance dari API bisa pake JMeter Ky. Misal buat ngecek waktu response yang dibutuhkan, jumlah concurrent users yg mampu dihandle, CPU/Memory usage, memory leak.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s