add new fitur api

This commit is contained in:
lawdfrogo 2025-05-27 11:11:54 +07:00
parent b0d7683e9c
commit ccfe72c347
4 changed files with 72 additions and 2 deletions

9
bruno.json Normal file
View File

@ -0,0 +1,9 @@
{
"version": "1",
"name": "costapy",
"type": "collection",
"ignore": [
"node_modules",
".git"
]
}

View File

@ -4,7 +4,7 @@ host = "localhost"
port = 11000
reloader = False
debug = False
server = 'gunicorn' # default = 'wsgiref'
server = 'wsgiref' # default = 'wsgiref'
session_opts = {
'session.type': 'file',

View File

@ -5,9 +5,11 @@
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
from bottle import Bottle, route
from bottle import Bottle, route, response, request
from config import directory
import json
import templates.plain.main as template_public
import modules.public.home as public_home
@ -21,3 +23,45 @@ def index():
}
}
return public_home.main().html(params)
@app.route('/api/<crud>', methods=['OPTIONS', 'GET', 'POST', 'PUT', 'DELETE'])
def list(crud):
#Menentukan tipe konten untuk response
response.content_type = 'application/json'
#Mengambil data dari request body
params = request.json
#Keluaran bawaan
keluaran = {
"status": "berhasil",
"message": "Anda Tidak dapat mengakses endpoint ini.",
"endpoint": f"/api/{crud}",
}
if crud == "create":
keluaran["status"] = "berhasil"
keluaran["message"] = "Dummy: selamat data anda telah berhasil disimpan."
keluaran["data"] = {
"food":params["food"]
}
elif crud == "read":
keluaran["status"] = "berhasil"
keluaran["message"] = "Dummy: data berhasil diambil."
keluaran["data"] = [
"banana",
"apple",
"marshmallow"
]
elif crud == "update":
keluaran["status"] = "berhasil"
keluaran["message"] = "Dummy: belum disediakan, silakan hubungi developer untuk menambahkan fitur ini."
elif crud == "delete":
keluaran["status"] = "berhasil"
keluaran["message"] = "Dummy: belum disediakan, silakan hubungi developer untuk menambahkan fitur ini."
else:
pass
return json.dumps(keluaran, indent=2).encode()

17
web.bru Normal file
View File

@ -0,0 +1,17 @@
meta {
name: web
type: http
seq: 10
}
get {
url: http://localhost:11000/api/create
body: json
auth: inherit
}
body:json {
{
"food":"Pasta"
}
}