Question about APIs
-
So I'm reading up on API's, partly in my quest to expand my knowledge. I have a few conceptual questions I hope someone can shed some light on for me.
API - I've always come across this as though it is a "simple command" to run or call. But then there are lines of code that are the API, and they get "called". In most cases the example is then what looks like an url, such as
https://my.example.com/api/v1/cloudron/status
(from https://docs.cloudron.io/api.html#tag/Cloudron/paths/~1cloudron~1status/get).so...
- I need to be able to write the code of the API in order to use it, and;
- the code that makes up the API is then saved as a file somewhere from which it is called (or run or activated or executed).
For 1) In many cases I should be able to replace whatever the examples are in an API with my own info for it to work, right?
For 2) it seems like these commands, saved in files, need to be accessible, either in/by a web browser, or by a CLI (either called by options or by making sure they are in the $PATH), right?
So, using the examples from https://docs.cloudron.io/api.html#tag/Cloudron/paths/~1cloudron~1status/get, does this mean I need to have these various APIs (saved in files) hosted on a local Apache instance or something, in order for me to be able to "call" them? But, how would that work since the API is
https://my.example.com/api/v1/cloudron/status
, and not localhost? ** Or would I actually run it fromlocalhost/status
, since (from the example) the file "status" is what contains the important info:{ "version": "5.1.0", "apiServerOrigin": "https://api.cloudron.io", "webServerOrigin": "https://cloudron.io", "provider": "linode", "cloudronName": "My Space", "footer": "© 2020 [Cloudron](https://cloudron.io) [Forum <i class=\"fa fa-comments\"></i>](https://forum.cloudron.io)", "adminFqdn": "my.example.com", "activated": true, "setup": { "active": false, "message": "Fetching SSL certificate ...", "errorMessage": null }, "restore": { "active": false, "message": "Downloading backups ...", "errorMessage": null } }
Or do I need to save all these API files in /opt, or /sbin or something like that?
I've been trying to read online tutorials, but like I mentioned in a similar post, most of these tuts assume a level of familiarity or grasp of the concepts, when for a user like me, lots doesn't make sense and the questions I have don't seem to be asked!Thanks everyone and anyone!
-
The API style in Cloudron you are referring to is commonly called REST API, although Cloudron does not strictly follow REST patterns. It can be used with a multitude of clients. Some are libraries to be used withing other programs and they exist for all programming languages by now I would guess. Some other clients are browsers or also commandline clients like CURL.
I think it might help you a lot to read up about REST APIs which should clarify things for you.
Just a simple example, without an access token (so using just public API), run the following on a terminal with curl installed:
curl -v https://my.<your cloudron domain>/api/v1/cloudron/status
-
@nebulon @girish Sorry to hijack this thread but its close enough to my topic/use case lol
I am attempting to use the Private API with an access token ( I was able to create one via the user GUI and via the Public API following the docs) But I am having trouble using the token on a GET API call...Will you please provide an example of how and where to use the token?
Some background: I am using Wappler.io to create the API GET call.
As mentioned I was able to create the POST action with a JSON payload using the advised syntax to generate an API token:
{
"username": "julia",
"password": "supersecret"
}But I am not sure how to apply the token on a GET call
Current output:{
"status": "Unauthorized",
"message": "Token required"
}Any insight and guidance is greatly appreciated!
+1 -