Context
Using Go context with SP client
Last updated
Was this helpful?
Was this helpful?
spClient := api.NewHTTPClient(&gosip.SPClient{AuthCnfg: auth})
endpoint := auth.GetSiteURL() + "/_api/web?$select=Title"
reqConf := &api.RequestConfig{
Context: context.Background(), // <- pass a context
}
data, err := spClient.Get(endpoint, reqConf)
if err != nil {
log.Fatalf("%v\n", err)
}
// spClient.Post(endpoint, body, reqConf) // generic POST
// generic DELETE helper crafts "X-Http-Method"="DELETE" header
// spClient.Delete(endpoint, reqConf)
// generic UPDATE helper crafts "X-Http-Method"="MERGE" header
// spClient.Update(endpoint, body, reqConf)
// CSOM helper (client.svc/ProcessQuery)
// spClient.ProcessQuery(endpoint, body, reqConf)config := &api.RequestConfig{
Context: context.Background(), // <- pass a context
}
sp := api.NewSP(client).Conf(config)
data, err := sp.Web().Lists().Select("Id,Title").Get()
if err != nil {
log.Fatalln(err)
}