From d7f3369e0afd8d8d0b8a7eb9c646cc4634aae7b2 Mon Sep 17 00:00:00 2001 From: valentinkolb Date: Wed, 27 Mar 2024 19:43:54 +0100 Subject: [PATCH] feat(qrApi): data now passed as query string For better use in markdown etc the data for the qr code is now passed als query string instead of the json body --- Readme.md | 4 ++-- qrApi/main.go | 28 +++++++++++++--------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Readme.md b/Readme.md index 59689e5..62f5342 100644 --- a/Readme.md +++ b/Readme.md @@ -124,7 +124,7 @@ zum Generieren von QR-Codes in SVG anbietet. #### API Route Das Package bietet die Route `GET /api/qr/v1` an, welche die folgenden -Parameter als json entgegennimmt: +Parameter als query string entgegennimmt: | Parameter | Datentyp | Beschreibung | |-------------------|-------------|------------------------------------------------------------------------------------------------| @@ -138,7 +138,7 @@ Parameter als json entgegennimmt: #### Beispiel ```bash -curl -X GET https://it.stuve.uni-ulm.de/api/qr/v1 -d '{"data": "https://stuve.uni-ulm.de"}' +curl -X GET https://it.stuve.uni-ulm.de/api/qr/v1?data=stuve.uni-ulm.de ``` ### LDAP API diff --git a/qrApi/main.go b/qrApi/main.go index 1a0a10e..dd3a5f1 100644 --- a/qrApi/main.go +++ b/qrApi/main.go @@ -16,16 +16,14 @@ import ( // this endpoint can be used to create qr codes // GET /api/qr/v1 // -// the endpoint expects the following request data: +// the endpoint expects the following query params: // -// { -// "data": "what to be encoded", -// "ecc": "error correction level ('L', 'M' (default), 'Q', 'H')", -// "scale": "scale of qr code (default 1), must be greater than 0", -// "border": "border of qr code (default 1), must be equal or greater than 0, one is equal to one qr-code 'pixel'" -// "color": "color of qr code (default #000000)" -// "colorBackground": "background color of qr code (default #FFFFFF)", -// } +// "data": "what to be encoded", +// "ecc": "error correction level ('L', 'M' (default), 'Q', 'H')", +// "scale": "scale of qr code (default 1), must be greater than 0", +// "border": "border of qr code (default 1), must be equal or greater than 0, one is equal to one qr-code 'pixel'" +// "color": "color of qr code (default #000000)" +// "colorBackground": "background color of qr code (default #FFFFFF)", // // if the user is authenticated successfully the endpoint returns and apis.RecordAuthResponse func InitQRApi(app *pocketbase.PocketBase, e *core.ServeEvent) error { @@ -37,12 +35,12 @@ func InitQRApi(app *pocketbase.PocketBase, e *core.ServeEvent) error { // get data from request data := struct { - Data string `json:"data"` - ECC string `json:"ecc"` - Scale int `json:"scale"` - Border int `json:"border"` - ColorDark string `json:"color"` - ColorLight string `json:"colorBackground"` + Data string `query:"data"` + ECC string `query:"ecc"` + Scale int `query:"scale"` + Border int `query:"border"` + ColorDark string `query:"color"` + ColorLight string `query:"colorBackground"` }{} if err := c.Bind(&data); err != nil { return apis.NewBadRequestError("Failed to read request data", err)