From 757447597d76cf3c6c94f9f9c53984cf04e87e98 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 19 Mar 2020 12:04:39 -0300 Subject: [PATCH] Bug 24908: Add text-formatted MARC support in /biblios/{biblio_id} This patch makes the route support requesting (through the Accept header) the MARC record to be output as formatted text as in $record->as_formatted. To test: 1. Apply the unit tests patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/biblios.t => FAIL: Tests fail 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Try the route with your favourite API testing tool (Postman?) => SUCCESS: Accept: text/plain returns the expected results => SUCCESS: Wrong Accept header returns a list of valid formats, and includes 'text/plain'. 6. Sign off :-D Signed-off-by: David Nind Signed-off-by: Jonathan Druart --- Koha/REST/V1/Biblios.pm | 8 +++++++- api/v1/swagger/paths/biblios.json | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index 121d66fbe3..221d217522 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -82,13 +82,19 @@ sub get { format => 'marc', text => $record->as_usmarc }, + txt => { + status => 200, + format => 'text/plain', + text => $record->as_formatted + }, any => { status => 406, openapi => [ "application/json", "application/marcxml+xml", "application/marc-in-json", - "application/marc" + "application/marc", + "text/plain" ] } ); diff --git a/api/v1/swagger/paths/biblios.json b/api/v1/swagger/paths/biblios.json index 530993ff33..4896b71f62 100644 --- a/api/v1/swagger/paths/biblios.json +++ b/api/v1/swagger/paths/biblios.json @@ -15,7 +15,8 @@ "application/json", "application/marcxml+xml", "application/marc-in-json", - "application/marc" + "application/marc", + "text/plain" ], "responses": { "200": { -- 2.20.1