You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Web APIs are applications that are designed for other computer programs or services to interoperate with, if you wanted to enable other web apps to use your previous app, you would do this as follows:
44
44
45
+
Always ensure any API's root path `@app.get("/")` function is kept, because Hal9 Web APIs use this endpoint to check the application's status.
46
+
47
+
Hal9 is able to run Python FastAPI or Flask apps.
48
+
49
+
### Fast API
45
50
```python deploy
46
51
from fastapi import FastAPI
47
52
import random
48
53
49
54
app = FastAPI()
50
55
51
56
@app.get("/")
57
+
defread_root():
58
+
return {"success": True}
59
+
60
+
@app.get("/roll")
52
61
asyncdefroll():
53
62
returnf"You rolled a {random.randint(1, 6)}!"
54
63
```
55
64
65
+
### Flask API
66
+
```python deploy
67
+
from flask import Flask, jsonify, request
68
+
from asgiref.wsgi import WsgiToAsgi # WSGI compatible with Hal9 launcher
69
+
import random
70
+
71
+
flaskapp = Flask(__name__)
72
+
73
+
@flaskapp.route("/", methods=['GET'])
74
+
defread_root():
75
+
return jsonify({"success": True})
76
+
77
+
@flaskapp.route("/roll", methods=['GET'])
78
+
defroll():
79
+
returnf"You rolled a {random.randint(1, 6)}!"
80
+
81
+
app = WsgiToAsgi(flaskapp)
82
+
```
83
+
56
84
When a chatbot generates an API, Hal9 automatically deploys and embeds the API endpoint; however, if you have to manually deploy an API you can accomplish this as follows:
0 commit comments