REST API Service
๐ Getting Started
REST API Service
๐ Getting Started
Quickstart
To use Embedchain as a REST API service, run the following command:
docker run --name embedchain -p 8080:8080 embedchain/rest-api:latest
Navigate to http://localhost:8080/docs to interact with the API. There is a full-fledged Swagger docs playground with all the information about the API endpoints.
โก Steps to get started
1
โ๏ธ Create an app
curl --request POST "http://localhost:8080/create?app_id=my-app" \
-H "accept: application/json"
curl --request POST "http://localhost:8080/create?app_id=my-app" \
-H "accept: application/json"
import requests
url = "http://localhost:8080/create?app_id=my-app"
payload={}
response = requests.request("POST", url, data=payload)
print(response)
const data = fetch("http://localhost:8080/create?app_id=my-app", {
method: "POST",
}).then((res) => res.json());
console.log(data);
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "http://localhost:8080/create?app_id=my-app"
payload := strings.NewReader("")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
2
๐๏ธ Add data sources
curl --request POST \
--url http://localhost:8080/my-app/add \
-d "source=https://www.forbes.com/profile/elon-musk" \
-d "data_type=web_page"
curl --request POST \
--url http://localhost:8080/my-app/add \
-d "source=https://www.forbes.com/profile/elon-musk" \
-d "data_type=web_page"
import requests
url = "http://localhost:8080/my-app/add"
payload = "source=https://www.forbes.com/profile/elon-musk&data_type=web_page"
headers = {}
response = requests.request("POST", url, headers=headers, data=payload)
print(response)
const data = fetch("http://localhost:8080/my-app/add", {
method: "POST",
body: "source=https://www.forbes.com/profile/elon-musk&data_type=web_page",
}).then((res) => res.json());
console.log(data);
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "http://localhost:8080/my-app/add"
payload := strings.NewReader("source=https://www.forbes.com/profile/elon-musk&data_type=web_page")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
3
๐ฌ Query on your data
curl --request POST \
--url http://localhost:8080/my-app/query \
-d "query=Who is Elon Musk?"
curl --request POST \
--url http://localhost:8080/my-app/query \
-d "query=Who is Elon Musk?"
import requests
url = "http://localhost:8080/my-app/query"
payload = "query=Who is Elon Musk?"
headers = {}
response = requests.request("POST", url, headers=headers, data=payload)
print(response)
const data = fetch("http://localhost:8080/my-app/query", {
method: "POST",
body: "query=Who is Elon Musk?",
}).then((res) => res.json());
console.log(data);
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "http://localhost:8080/my-app/query"
payload := strings.NewReader("query=Who is Elon Musk?")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
4
๐ (Optional) Deploy your app to Embedchain Platform
curl --request POST \
--url http://localhost:8080/my-app/deploy \
-d "api_key=ec-xxxx"
curl --request POST \
--url http://localhost:8080/my-app/deploy \
-d "api_key=ec-xxxx"
import requests
url = "http://localhost:8080/my-app/deploy"
payload = "api_key=ec-xxxx"
response = requests.request("POST", url, data=payload)
print(response)
const data = fetch("http://localhost:8080/my-app/deploy", {
method: "POST",
body: "api_key=ec-xxxx",
}).then((res) => res.json());
console.log(data);
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "http://localhost:8080/my-app/deploy"
payload := strings.NewReader("api_key=ec-xxxx")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
And youโre ready! ๐
If you run into issues, please feel free to contact us using below links:
Was this page helpful?
On this page