Rechnernetze / Kommunikationssysteme

Praktikumsversuch Representational State Transfer (REST) und CORS

Dieses Praktikum dient dem Verständnis des REST-Paradigmas und der praktischen Erprobung einer REST-API.

Vorbereitung

REST-API Prinzipien

HATEOAS

Die Server-Antwort sollte Weiterverfolgungs-Links enthalten, z.B. nach GET-Request eines Quiz alle möglichen Folgeaktionen:

"_links": {
            "self":     { "href": "/api/quizzes/123" },
            "solve":    { "href": "/api/quizzes/123/solve", "method": "POST" },
            "update":   { "href": "/api/quizzes/123", "method": "PUT" }
            "delete":   { "href": "/api/quizzes/123", "method": "DELETE" }
            "completed":{ "href": "/api/quizzes/completed", "method": "GET" }
        }
        
        

Das Ziel ist eine weitgehende Entkopplung des Clients von der Server-API. Arten der Umsetzung:

Same-Origin Policy (SOP)

Cross-Origin Resource Sharing (CORS)

Aufgaben

Wir nutzen für unserer Versuche CURL und die API des WebQuiz-Server auf Server idefix.

API WebQuiz

Vorgang Methode URL (/api/…) Daten (JSON) Antwort (JSON) HTTP Auth. Eig.
Register new user POST register email, password   200, 400    
Create a quiz POST quizzes title, text, options, answer id, title, text, options 200, 404 x  
Get a quiz GET quizzes/id   id, title, text, options 200, 404 x  
Get all quizzes GET quizzes?page=0   Array 200 x  
Solving a quiz POST quizzes/id/solve [0,1] success, feedback 200, 404 x  
Get all completed quizzes GET quizzes/completed   Array 200 x  
Deleting a quiz DELETE quizzes/id     204, 403, 404 x x

CURL

Literatur

Fakultativ

Zugriff mittels JavaScript