From 3ee2459035c66bea2e0d5591d20f707e4c4bca9d Mon Sep 17 00:00:00 2001
From: hahn <axel.hahn@iml.unibe.ch>
Date: Tue, 16 Jun 2020 15:20:49 +0200
Subject: [PATCH] task#3869 - initial stuff for API small FIXES in server api:
 contenttype, JSON pretty print

---
 public_html/api/index.php | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/public_html/api/index.php b/public_html/api/index.php
index 4ded2b2a..48082084 100644
--- a/public_html/api/index.php
+++ b/public_html/api/index.php
@@ -6,7 +6,7 @@
  * GET  /api/v1/projects/
  * GET  /api/v1/project/[ID]/build/[name-of-branch]
  * POST /api/v1/project/[ID]/build/[name-of-branch]
- * get  /api/v1/project/[ID]/phases
+ * GET  /api/v1/project/[ID]/phases
  * 
  * ----------------------------------------------------------------------
  * 2020-06-16  v0.9  <axel.hahn@iml.unibe.ch>  
@@ -22,14 +22,8 @@
     
     $sDirClasses=__DIR__.'/../deployment/classes/';
     require_once($sDirClasses.'/project.class.php');
-    
     require_once($sDirClasses.'logger.class.php');
 
-    $aApiItems=array(
-        'project',
-        'projects',
-        'help',
-    );
     $iMaxAge=60;
     
     // ----------------------------------------------------------------------
@@ -70,7 +64,7 @@
      */
     function _done($Data){
         echo is_array($Data) 
-            ? json_encode($Data, 1, JSON_PRETTY_PRINT)
+            ? json_encode($Data, JSON_PRETTY_PRINT)
             : $Data
             ;
         die();
@@ -116,7 +110,9 @@
     // ----------------------------------------------------------------------
     // MAIN
     // ----------------------------------------------------------------------
-
+    if (!$bDebug){
+        header('Content-Type: application/json');
+    }
     _wd('Start: '.date('Y-m-d H:i:s').'<style>body{background:#eee; color:#456;}
             .debug{background:#ddd; margin-bottom: 2px;}
          </style>');
@@ -148,15 +144,11 @@
 
 
     if(!$sApiVersion){
-        _quit('no paramm for api version was found.');
+        _quit('ERROR: no param for api version was found.');
     }
     if(!$sApiItem){
-        _quit('ERROR: no paramm for item was found.');
+        _quit('ERROR: no param for item was found.');
     }
-    if(!in_array($sApiItem, $aApiItems)){
-       _quit('ERROR: item ['.$sApiItem.'] is invalid.');
-    }
-    
     
     
     switch ($sApiVersion){
@@ -245,7 +237,6 @@
                     break;;
                     
                 default:
-                    // unreachable - see in_array before switch
                     _quit('ERROR: item ['.$sApiItem.'] is invalid.');
             }
             break;
-- 
GitLab