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
Not sure how useful this will be but I found myself needing to use my database over HTTP in serverless cloud functions. Using Websockets there would have several issues do to their short-lived nature (performance overheads, resource usage, connection disruptions, etc...). I noticed that the python sdk contains this class, which is great, but I think this also needs it. Bare in mind I have never used rust.
classSurrealHTTP{constructor(url,ns,db,auth){this.url=url;this.ns=ns;this.db=db;this.auth=auth;}asyncquery(sql,bindings){letconfig={headers: {'NS': this.ns,'DB': this.db,'Accept': 'application/json'},params: bindings// bind variables in the request params};// auth configuration based on whether JWT token or user and password are usedif(this.auth.token){config.headers['Token']=`${this.auth.token}`;}else{// Basic authenticationconfig.auth={username: this.auth.username,password: this.auth.password};}try{constresponse=awaitaxios.post(`${this.url}/sql`,sql,config);if(response.data[0].status!=='OK'){thrownewError('Server responded with a status other than OK.');}returnresponse.data;}catch(error){console.error(error);returnnull;}}}
EDIT: Added JWT auth
The text was updated successfully, but these errors were encountered:
Not sure how useful this will be but I found myself needing to use my database over HTTP in serverless cloud functions. Using Websockets there would have several issues do to their short-lived nature (performance overheads, resource usage, connection disruptions, etc...). I noticed that the python sdk contains this class, which is great, but I think this also needs it. Bare in mind I have never used rust.
EDIT: Added JWT auth
The text was updated successfully, but these errors were encountered: