sqlitecloud / sdk

Official SDK repository for SQLite Cloud databases and nodes.
https://sqlitecloud.io
29 stars 3 forks source link

HTTP PUT - Endpoint Not Found #30

Open drveresh opened 3 weeks ago

drveresh commented 3 weeks ago

I am getting the below error with the EdgeFunction (EF) when trying to update a record of table of SQLite database instance. The error indicates neither a real technical issue nor a meaningful(unauthorized) issue. Please clarify and address this issue asap, I'm blocked on this.

{
    "error": {
        "status": "404",
        "title": "Not found",
        "detail": "PUT /v2/functions/myFunction was not found"
    }
}

Below is the EF code:

if ( request.method === "PUT" ) {
        const query = putQuery(request); //Returns "UPDATE Temp set status='${status}' WHERE id=${id}"
        result = await connection.sql(query);
        message = `Number of updates: ${result.length}`;
}

In the Console Logs, it is definitely a PUT type request created via local POSTMAN app.

TizianoT commented 3 weeks ago

@drveresh Executing When executing an edge function, you should use either the GET or POST methods, depending on whether you need to include a request body.

The specific actions performed by the edge function are independent of the HTTP method used. The typical REST method conventions do not apply to edge functions in this context. You can think of an edge function as a piece of code that runs close to your database and can perform any operation you define. You trigger this code using a GET or POST request.

Within your edge function, you can access:

Authorization When creating an edge function, you have the option to assign an API key to it.

If an API key is assigned, any calls to the edge function will automatically authenticate access to the associated database using that API key.

If you choose not to assign an API key, you will need to provide it when invoking the edge function. The API key can be included in the request as a query parameter named "apikey" or within the body.

For more information, you can refer to this discussion about securing edge functions with an API key.

drveresh commented 3 weeks ago

Got it, thanks for the clarification. Please update the documentation accordingly, or else users will assume the same.

Also, please update those error messages to convey the appropriate reason, else it is confusing allot similar to other error messages.