add new fitur api
This commit is contained in:
parent
b0d7683e9c
commit
ccfe72c347
9
bruno.json
Normal file
9
bruno.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"version": "1",
|
||||||
|
"name": "costapy",
|
||||||
|
"type": "collection",
|
||||||
|
"ignore": [
|
||||||
|
"node_modules",
|
||||||
|
".git"
|
||||||
|
]
|
||||||
|
}
|
@ -4,7 +4,7 @@ host = "localhost"
|
|||||||
port = 11000
|
port = 11000
|
||||||
reloader = False
|
reloader = False
|
||||||
debug = False
|
debug = False
|
||||||
server = 'gunicorn' # default = 'wsgiref'
|
server = 'wsgiref' # default = 'wsgiref'
|
||||||
|
|
||||||
session_opts = {
|
session_opts = {
|
||||||
'session.type': 'file',
|
'session.type': 'file',
|
||||||
|
46
handler.py
46
handler.py
@ -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.
|
# 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/.
|
# 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
|
from config import directory
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
import templates.plain.main as template_public
|
import templates.plain.main as template_public
|
||||||
import modules.public.home as public_home
|
import modules.public.home as public_home
|
||||||
|
|
||||||
@ -21,3 +23,45 @@ def index():
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return public_home.main().html(params)
|
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()
|
Loading…
Reference in New Issue
Block a user