Sure, here's an example folder structure and boilerplate code for creating a REST API in Frapee, assuming you want to use Python:
- Create a folder for your Frapee app:
bashmkdir parlo
cd parlo
- Create a virtual environment and activate it:
bashpython3 -m venv venv
source venv/bin/activate
- Install Frapee:
pip install frappe
- Generate a new app skeleton using Frapee CLI:
arduinofrappe new-app parlo
- Create a new route for your REST API by adding a new file to the
parlo
app folder, for example:
python# parlo/api.py
import frappe
@frappe.whitelist(allow_guest=True)
def get_intend():
# TODO: Implement your API logic here
return {'status': 'success', 'message': 'Hello, world!'}
- Register the new route in
hooks.py
by adding the following code:
makefile# parlo/hooks.py
app_name = "parlo"
# include api.py
app_include_js = "/assets/parlo/js/parlo.js"
app_include_css = "/assets/parlo/css/parlo.css"
web_include_js = "/assets/parlo/js/parlo-web.js"
web_include_css = "/assets/parlo/css/parlo-web.css"
# Add any new Frappe Hooks below
# docs: https://frappeframework.com/docs/user/en/guides/app-development/hooks
- Add your new app to the
installed_app
list insite_config.json
:
bash# site_config.json
{
"db_name": "your_db_name",
"db_password": "your_db_password",
"developer_mode": 1,
"disable_website_cache": 1,
"installed_apps": ["parlo"],
"limits": {
"space_usage": {
"enabled": 1
}
}
}
- Start the Frapee development server and test your API:
graphql# Start the server
bench start
# Test the API by sending a GET request to http://localhost:8000/api/method/parlo.api.get_intend
That's it! Of course, this is just a basic example to get you started. You'll need to fill in the actual implementation of get_intend()
with your own logic. Good luck!
Sure, here's an example test case using the Python requests
library to test your get_intend()
API endpoint:
pythonimport requests
# Set the base URL for your Frapee site
base_url = 'http://localhost:8000'
# Define the endpoint URL for your API method
endpoint_url = base_url + '/api/method/parlo.api.get_intend'
def test_get_intend():
# Send a GET request to your API endpoint
response = requests.get(endpoint_url)
# Verify that the response is successful (status code 200)
assert response.status_code == 200
# Verify that the response body contains the expected data
expected_data = {'status': 'success', 'message': 'Hello, world!'}
assert response.json() == expected_data
Note that in this example, we assume that you're running your Frapee development server on http://localhost:8000
. You should adjust the base_url
variable to match the actual URL of your server. Also, make sure that the get_intend()
method is actually returning a JSON response with the expected data. If not, adjust the expected_data
variable accordingly.