diff --git a/public/src/examples.html b/public/src/examples.html index 45848df..28f1eac 100644 --- a/public/src/examples.html +++ b/public/src/examples.html @@ -294,25 +294,32 @@ response.raise_for_status()
SDK coming soon. In the meantime, use the HTTP example below — it works with any HTTP client.
package main
import (
+ "bytes"
+ "encoding/json"
+ "io"
+ "net/http"
"os"
- docfast "github.com/docfast/docfast-go"
)
-func main() {
- client := docfast.New("df_pro_your_api_key")
-
- pdf, err := client.HTML("<h1>Hello</h1><p>Generated with DocFast</p>", &docfast.PDFOptions{
- Format: "A4",
- Margin: &docfast.Margin{Top: "20mm", Bottom: "20mm"},
+func main() {
+ body, _ := json.Marshal(map[string]string{
+ "html": "<h1>Hello</h1><p>Generated with DocFast</p>",
})
- if err != nil {
- panic(err)
- }
- os.WriteFile("output.pdf", pdf, 0644)
+
+ req, _ := http.NewRequest("POST", "https://docfast.dev/v1/convert/html", bytes.NewReader(body))
+ req.Header.Set("Authorization", "Bearer "+os.Getenv("DOCFAST_API_KEY"))
+ req.Header.Set("Content-Type", "application/json")
+
+ resp, err := http.DefaultClient.Do(req)
+ if err != nil { panic(err) }
+ defer resp.Body.Close()
+
+ pdf, _ := io.ReadAll(resp.Body)
+ os.WriteFile("output.pdf", pdf, 0644)
}