Hi,
I need to code an API on top of frappe and don’t want to use the provided REST API for several reasons.
I am searching for some utils that will help me in designing REST API with frappe.
route easily the request to the right method such as @app.route in flask. (parameter support)
build json response easily
redirect
i know that i can customize the frappe.local.response but maybe there are some higher levels API’s i don’t know
Can you perhaps say a bit more about what you’re trying to do? I can’t really imagine why you would want to implement a comprehensive RESTful interface on top of the one that already exists.
Hi,
no RPC is not what i am looking for.
For exemple i want to implement the following endpoints:
resource order:
a. GET /order retrieve list of order (Already supported with built in API)
b. GET /order/{order-id} retrieve specific order (Already supported with built in API)
c. GET /order/{order-id}/tracking retrieve tracking of specific order (not supported, i need to redesign the order doc to add tracking link to it which is not available at order creation)
d. if i want the call to triger some action i have to us RPC what i don’t want
i also want to choose which fields i want the API user to see. i also need to aggregate information from other doctype etc
Thanks for your reply.
i will try your options.
I post here what i implemented currently:
I defined one whitelisted method that will be in charge of “routing” the request to the right handler handle_request. I defined a base handler that has four methods: handle_get, handle_post, handle_put, handle_delete
then according to the frappe.request.path path i am routing the request to an handler that inherit from the base handler.
The downside of my solution is that i need to implement all the abstraction / utils of standards backend frameworks but i can use the frappe API to handle easily the requests.
Using framework like FastAPI or Flask will solve my problem but i will not be able to use the frappe API and will have to define tons of whitelisted methods. This is the trade-off i think
Tell me if i’m wrong
Thanks
Sorry but i still not understand.
What i want to do now is that:
Deploy a fastapi app within the bench that uses data of an existing site by connecting to it.
could you tell me if the below step are the right ones
installing the fastapi frappe app
run unvicorn command with the right SITE_NAME and SITES_PATH on port 3000 (for exemple)
edit the nginx.cnf within the config dir of the bench and add a new server that listen to port 3000
if it’s right i have one question, how to do the step 2 ? i can run the uvicorn command via ssh and persist it after exit or there is a more stable way ?
sorry if i lack knowledge devops is not my domain but i want to learn !
Thanks a lot @revant_one
supervisor is used by frappe, check the ~/frappe-bench/config/supervisor.conf for reference, check how the socketio and gunicorn runs. Make one more file that runs your app and place it in /etc/supervisor/conf.d/fast.conf. Restart supervisor after that.
Thanks @revant_one for your help i follow your advise and i think i managed it to work i am sharing here the content of the .conf file i created within the /etc/supervisor/conf.d dir
now i have to edit the conf file of nginx but i have the same problem as above, how to persist the changes even after runing bench setup nginx or same king of commands that override the nginx.conf
Sorry but i don’t know how to edit the nginx.conf. i am trying to use the above exemple you sent but as you said it’s for the first solution not the one i want to use.
I want to redirect incoming request to my api endpoint (let’s say) api.domain.com to the api app that’s run on port 3000 on the server. i am using the below conf
I finally found how to solve my two last problem (nginx conf persistance and the conf itself).
I simple created the follow conf file in the /etc/nginx/conf.d dir then restart nginx