Parcourir la source

Add all files.

cixo il y a 11 mois
Parent
commit
4f1e4370c8
7 fichiers modifiés avec 148 ajouts et 0 suppressions
  1. 2 0
      api/.htaccess
  2. 5 0
      api/get.php
  3. 5 0
      api/html-sample.php
  4. 113 0
      api/index.php
  5. 5 0
      api/post.php
  6. 5 0
      api/raw-sample.php
  7. 13 0
      api/sample.php

+ 2 - 0
api/.htaccess

@@ -0,0 +1,2 @@
+RewriteEngine on
+RewriteRule ^([^\.]+)$ $1.php [NC,L]

+ 5 - 0
api/get.php

@@ -0,0 +1,5 @@
+<?php
+
+header("Content-Type: application/json");
+
+echo(json_encode($_GET));

+ 5 - 0
api/html-sample.php

@@ -0,0 +1,5 @@
+<?php
+
+header("Content-type: text/html");
+
+echo("This is sample text/html response!");

+ 113 - 0
api/index.php

@@ -0,0 +1,113 @@
+<!DOCTYPE html>
+
+<html>
+    <head>
+        <meta charset="UTF-8">
+        <title>SampleREST</title>
+
+        <style>
+            body {
+                margin: 0px;
+                padding: 0px;
+                background: #222;
+                color: white;
+                font-size: 18px;
+                font-family: sans-serif;
+            }
+
+            h1 {
+                color: orange;
+            }
+
+            .container {
+                width: 60%;
+                margin-left: 10%;
+                margin-right: 10%;
+                margin-top: 40px;
+                margin-bottom: 40px;
+                padding-left: 10%;
+                padding-right: 10%;
+                padding-top: 20px;
+                padding-bottom: 20px;
+                border-radius: 20px;
+                border: 2px solid orange;
+            }
+
+            a {
+                color: white;
+                font-weight: bold;
+                transition: color 0.5s;
+            }
+
+            a:hover {
+                color: gray;  
+            }
+        </style>    
+
+        <script type="text/javascript">
+            document.addEventListener("DOMContentLoaded", () => {
+                const list_to_prepare = document.querySelector(".copy-from");
+                let home_location = document.location.toString();
+
+                if (home_location[home_location.length - 1] != "/") {
+                    home_location += "/";
+                }
+
+                list_to_prepare.childNodes.forEach(link => {
+                    link.innerText = home_location + link.innerText;
+                });
+            });
+        </script>
+    </head>
+
+    <body>
+        <div class="container">
+            <h1>Hello!</h1>
+            <p>
+                This is sample, super simple REST api for tutorial. It could
+                response in JSON, HTML and send You JSON response with data 
+                sentnby data in HTTP body (POST) or by parameters given in 
+                URL (GET).
+            </p>
+        </div>
+
+        <ul class="container">
+            <li>    
+                <a href="./get">/get</a> - This return You JSON with 
+                data sent by URL parameters (GET).
+            </li>
+
+            <li>
+                <a href="./post">/post</a> - This return You JSON with 
+                data sent by body of HTTP request (POST).
+            </li>
+
+            <li>
+                <a href="./sample">/sample</a> - This return You sample
+                static JSON.
+            </li>
+
+            <li>
+                <a href="./html-sample">/html-sample</a> - This return You 
+                static HTML response.
+            </li>
+
+            <li>
+                <a href="./plain-sample">/raw-sample</a> - This return You
+                static text/plain response.
+            </li>
+        </ul>
+    
+        <div class="container">
+            <h4>You can copy endpoints from list:</h4>
+
+            <ul class="copy-from">
+                <li>get</li>
+                <li>post</li>
+                <li>sample</li>
+                <li>html-sample</li>
+                <li>plain-sample</li>
+            </ul>
+        </div>
+    </body>
+</html>

+ 5 - 0
api/post.php

@@ -0,0 +1,5 @@
+<?php
+
+header("Content-Type: application/json");
+
+echo(json_encode($_POST));

+ 5 - 0
api/raw-sample.php

@@ -0,0 +1,5 @@
+<?php
+
+header("Content-type: text/plain");
+
+echo("This is sample text/plain response!");

+ 13 - 0
api/sample.php

@@ -0,0 +1,13 @@
+<?php
+
+header("Content-Type: application/json");
+
+$response = [];
+$response['content'] = 'Sample content, which is sending by REST api in JSON.';
+$response['title'] = 'Sample';
+$response['object'] = [];
+$response['object']['x'] = 10;
+$response['object']['y'] = 20;
+$response['object']['z'] = 30;
+
+echo(json_encode($response));