getting-started.mdx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. ---
  2. title: "🌍 Getting Started"
  3. ---
  4. ## Quickstart
  5. To use Embedchain as a REST API service, run the following command:
  6. ```bash
  7. docker run --name embedchain -p 8080:8080 embedchain/rest-api:latest
  8. ```
  9. Navigate to [http://localhost:8080/docs](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.
  10. ![Swagger Docs Screenshot](https://github.com/embedchain/embedchain/assets/73601258/299d81e5-a0df-407c-afc2-6fa2c4286844)
  11. ## ⚡ Steps to get started
  12. <Steps>
  13. <Step title="⚙️ Create an app">
  14. <Tabs>
  15. <Tab title="cURL">
  16. ```bash
  17. curl --request POST "http://localhost:8080/create?app_id=my-app" \
  18. -H "accept: application/json"
  19. ```
  20. </Tab>
  21. <Tab title="python">
  22. ```python
  23. import requests
  24. url = "http://localhost:8080/create?app_id=my-app"
  25. payload={}
  26. response = requests.request("POST", url, data=payload)
  27. print(response)
  28. ```
  29. </Tab>
  30. <Tab title="javascript">
  31. ```javascript
  32. const data = fetch("http://localhost:8080/create?app_id=my-app", {
  33. method: "POST",
  34. }).then((res) => res.json());
  35. console.log(data);
  36. ```
  37. </Tab>
  38. <Tab title="go">
  39. ```go
  40. package main
  41. import (
  42. "fmt"
  43. "net/http"
  44. "io/ioutil"
  45. )
  46. func main() {
  47. url := "http://localhost:8080/create?app_id=my-app"
  48. payload := strings.NewReader("")
  49. req, _ := http.NewRequest("POST", url, payload)
  50. req.Header.Add("Content-Type", "application/json")
  51. res, _ := http.DefaultClient.Do(req)
  52. defer res.Body.Close()
  53. body, _ := ioutil.ReadAll(res.Body)
  54. fmt.Println(res)
  55. fmt.Println(string(body))
  56. }
  57. ```
  58. </Tab>
  59. </Tabs>
  60. </Step>
  61. <Step title="🗃️ Add data sources">
  62. <Tabs>
  63. <Tab title="cURL">
  64. ```bash
  65. curl --request POST \
  66. --url http://localhost:8080/my-app/add \
  67. -d "source=https://www.forbes.com/profile/elon-musk" \
  68. -d "data_type=web_page"
  69. ```
  70. </Tab>
  71. <Tab title="python">
  72. ```python
  73. import requests
  74. url = "http://localhost:8080/my-app/add"
  75. payload = "source=https://www.forbes.com/profile/elon-musk&data_type=web_page"
  76. headers = {}
  77. response = requests.request("POST", url, headers=headers, data=payload)
  78. print(response)
  79. ```
  80. </Tab>
  81. <Tab title="javascript">
  82. ```javascript
  83. const data = fetch("http://localhost:8080/my-app/add", {
  84. method: "POST",
  85. body: "source=https://www.forbes.com/profile/elon-musk&data_type=web_page",
  86. }).then((res) => res.json());
  87. console.log(data);
  88. ```
  89. </Tab>
  90. <Tab title="go">
  91. ```go
  92. package main
  93. import (
  94. "fmt"
  95. "strings"
  96. "net/http"
  97. "io/ioutil"
  98. )
  99. func main() {
  100. url := "http://localhost:8080/my-app/add"
  101. payload := strings.NewReader("source=https://www.forbes.com/profile/elon-musk&data_type=web_page")
  102. req, _ := http.NewRequest("POST", url, payload)
  103. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  104. res, _ := http.DefaultClient.Do(req)
  105. defer res.Body.Close()
  106. body, _ := ioutil.ReadAll(res.Body)
  107. fmt.Println(res)
  108. fmt.Println(string(body))
  109. }
  110. ```
  111. </Tab>
  112. </Tabs>
  113. </Step>
  114. <Step title="💬 Query on your data">
  115. <Tabs>
  116. <Tab title="cURL">
  117. ```bash
  118. curl --request POST \
  119. --url http://localhost:8080/my-app/query \
  120. -d "query=Who is Elon Musk?"
  121. ```
  122. </Tab>
  123. <Tab title="python">
  124. ```python
  125. import requests
  126. url = "http://localhost:8080/my-app/query"
  127. payload = "query=Who is Elon Musk?"
  128. headers = {}
  129. response = requests.request("POST", url, headers=headers, data=payload)
  130. print(response)
  131. ```
  132. </Tab>
  133. <Tab title="javascript">
  134. ```javascript
  135. const data = fetch("http://localhost:8080/my-app/query", {
  136. method: "POST",
  137. body: "query=Who is Elon Musk?",
  138. }).then((res) => res.json());
  139. console.log(data);
  140. ```
  141. </Tab>
  142. <Tab title="go">
  143. ```go
  144. package main
  145. import (
  146. "fmt"
  147. "strings"
  148. "net/http"
  149. "io/ioutil"
  150. )
  151. func main() {
  152. url := "http://localhost:8080/my-app/query"
  153. payload := strings.NewReader("query=Who is Elon Musk?")
  154. req, _ := http.NewRequest("POST", url, payload)
  155. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  156. res, _ := http.DefaultClient.Do(req)
  157. defer res.Body.Close()
  158. body, _ := ioutil.ReadAll(res.Body)
  159. fmt.Println(res)
  160. fmt.Println(string(body))
  161. }
  162. ```
  163. </Tab>
  164. </Tabs>
  165. </Step>
  166. <Step title="🚀 (Optional) Deploy your app to Embedchain Platform">
  167. <Tabs>
  168. <Tab title="cURL">
  169. ```bash
  170. curl --request POST \
  171. --url http://localhost:8080/my-app/deploy \
  172. -d "api_key=ec-xxxx"
  173. ```
  174. </Tab>
  175. <Tab title="python">
  176. ```python
  177. import requests
  178. url = "http://localhost:8080/my-app/deploy"
  179. payload = "api_key=ec-xxxx"
  180. response = requests.request("POST", url, data=payload)
  181. print(response)
  182. ```
  183. </Tab>
  184. <Tab title="javascript">
  185. ```javascript
  186. const data = fetch("http://localhost:8080/my-app/deploy", {
  187. method: "POST",
  188. body: "api_key=ec-xxxx",
  189. }).then((res) => res.json());
  190. console.log(data);
  191. ```
  192. </Tab>
  193. <Tab title="go">
  194. ```go
  195. package main
  196. import (
  197. "fmt"
  198. "strings"
  199. "net/http"
  200. "io/ioutil"
  201. )
  202. func main() {
  203. url := "http://localhost:8080/my-app/deploy"
  204. payload := strings.NewReader("api_key=ec-xxxx")
  205. req, _ := http.NewRequest("POST", url, payload)
  206. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  207. res, _ := http.DefaultClient.Do(req)
  208. defer res.Body.Close()
  209. body, _ := ioutil.ReadAll(res.Body)
  210. fmt.Println(res)
  211. fmt.Println(string(body))
  212. }
  213. ```
  214. </Tab>
  215. </Tabs>
  216. </Step>
  217. </Steps>
  218. And you're ready! 🎉
  219. If you run into issues, please feel free to contact us using below links:
  220. <Snippet file="get-help.mdx" />