Institute of Computer Science
  1. Courses
  2. 2021/22 spring
  3. Enterprise System Integration (MTAT.03.229)
ET
Log in

Enterprise System Integration 2021/22 spring

  • Home
  • Lectures
  • Practicals
  • Assignements
  • Project and exam
  • Message Board

Part 3: Testing API

This application provides the following endpoints:

MethodURLAction
POST/api/publishersAdd a new publisher
GET/api/publishersRetrieve all publishers
DELETE/api/publishersDelete all publisher
PUT/api/publishers/{id}Update a publisher by :id
DELETE/api/publishers/{id}Delete a publisher by :id
POST/api/publishers/{publisherId}/advsCreate/Add an advertisement for a publisher
GET/api/publishers/{publisherId}/advsRetrieve all advertisements of a publisher
GET/api/advs/{advsId}/publishersRetrieve all publishers of an advertisement
GET/api/advs/{id}Retrieve a specific advertisement by id
PUT/api/advs/{id}Update a specific advertisement by id
DELETE/api/advs/{id}Delete a specific advertisement by id
DELETE/api/publishers/{publisherId}/advs/{advsId}Delete a specific advertisement by id from a specific publisher

Examples

Add a publisher (Postman):

Add an advertisement to publisher with id=1

Add a publisher (PHP - cURL):

Note: You will need an HTTP sever to run these PHP files. Navigate to the folder where these files are located and start the server as follow and then in your browser go to http://127.0.0.1:9000 to view the results:

cd path/to/your/app or PHP files
php -S 127.0.0.1:9000
<?php 
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => 'localhost:8080/api/publishers',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "name":"Media.net",
    "publisher_address":"New York, USA",
    "publisher_contact":"info@media.net"
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>

Retrieve all publishers (PHP - cURL):

<?php
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => 'localhost:8080/api/publishers',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
  1. Part 1: Initial Scenario
  2. Part 2: Building API
  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment