simple no-cost json storage API

Post your working scripts, libraries and tools.
sashaatx
Posts: 350
Joined: 27 May 2021, 08:27
Contact:

simple no-cost json storage API

13 Feb 2024, 02:12

warning: insecure. dont store sens data.
There was a simple no cost json from this github called anon storage, I believe. https://github.com/samfisherirl/public-apis
I found this in its stead in the pull requests. I use it for testing non-commercial api data and for basic tasks between computers like sharing a local path.
https://getpantry.cloud/

Code: Select all

; docs https://getpantry.cloud/

if A_LineFile = A_ScriptFullPath && !A_IsCompiled
    pantryExample()

pantryExample() 
{
    ; Example usage:
    PantryAPI.PantryID := "YOUR_PANTRY_ID" ; Set your Pantry ID (akin to api key)
    PantryAPI.BasketName := "YOUR_BASKET_NAME" ; Set your Basket Name (akin to repo name)
    ; https://getpantry.cloud/#
    MsgBox PantryAPI.NewBasket()
    ; Get basket contents
    MsgBox PantryAPI.GetBasket()
    ; Update basket contents
    NewData := '{"newKey": "newValue"}'
    MsgBox PantryAPI.UpdateBasket(NewData)
    ; Delete basket
    MsgBox PantryAPI.DeleteBasket()
}

class PantryAPI {
    static PantryID := "" ; Your Pantry ID here
    static BasketName := "" ; Your Basket Name here
    static BaseURL := "https://getpantry.cloud/apiv1/pantry/"
    static basket :=  "/basket/"
    static Headers := Map("Content-Type", "application/json")
    
    static NewBasket() 
    {
        Response := this.SendRequest("POST", "")
        return Response
    }
    
    ; Method to update the contents of a basket
    static UpdateBasket(newData) {
        Url := this.BaseURL
        Response := this.SendRequest("PUT", newData)
        return Response
    }

    ; Method to get the contents of a basket
    static GetBasket() {
        Url := this.BaseURL
        Response := this.SendRequest("GET")
        return Response
    }

    ; Method to delete a basket
    static DeleteBasket() {
        Url := this.BaseURL
        Response := this.SendRequest("DELETE")
        return Response
    }

    ; Helper method to send an HTTP request
    static SendRequest(Method, Data := "") {
        HttpRequest := ComObject("WinHttp.WinHttpRequest.5.1")
        HttpRequest.Open(Method, PantryAPI.BaseURL . PantryAPI.PantryID . PantryAPI.basket . PantryAPI.BasketName, false)
        for Header, Value in PantryAPI.Headers
            HttpRequest.SetRequestHeader(Header, Value)
        if (Data != "")
            HttpRequest.Send(Data)
        else
            HttpRequest.Send()
        return HttpRequest.ResponseText
    }
}

Last edited by sashaatx on 29 Feb 2024, 18:12, edited 5 times in total.
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :
william_ahk
Posts: 504
Joined: 03 Dec 2018, 20:02

Re: simple no-cost json storage API

22 Feb 2024, 01:26

Looks really good. But seems to auto-delete data after inactivity. Use only for prototyping I suppose.

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: No registered users and 17 guests