

Testing curl to matrix.org
source link: https://gist.github.com/RickCogley/69f430d4418ae5498e8febab44d241c9
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Testing the matrix.org client-server API
Matrix is:
an open standard for decentralised communication, providing simple HTTP APIs and open source reference implementations for securely distributing and persisting JSON over an open federation of servers.
It's pretty fantastic, if you think on the massive problem of fragmentation all across the web. They've created an easy to use API, and you can do a kludgy test using curl from the terminal (*nix
, mac, win). See: http://matrix.org/docs/howtos/client-server.html
It's pretty straightforward to do a quick test. I have an account at https://matrix.org / https://vector.im, so I used that to get a token.
curl -XPOST -d '{"type":"m.login.password", "user":"myuserid", "password":"mypass"}' "https://matrix.org/_matrix/client/r0/login"
That returns the token in some json:
{"access_token":"MDAxO...blahblah","refresh_token":"MDAxO...blahblah","home_server":"matrix.org","user_id":"@myuserid:matrix.org"}
Now you have the access_token
you can use in your curl command, when hitting the API, and I understand that this token does not expire. Also get the ID from a room you create at matrix.org (get room properties via the web UI), which for me was !QaRABAkxDBNukDoCOY
. The !
is problematic in shells so, escape it after you paste the room id into your curl command.
Think of the curl command as a really, really simple analogue to a proper matrix.org client like vector.im, so, the URL of the API is that of your home server; in this case matrix.org. (Thanks @Half-Shot)
curl -XPOST -d '{"msgtype":"m.text", "body":"Hello from '"$USER"'"}' "https://matrix.org/_matrix/client/r0/rooms/\!QaRABAkxDBNukDoCOY:matrix.org/send/m.room.message?access_token=MDAxO...blahblah"
You can use shell variables in your curl command, but you have to split the data part using single quotes. The json's structure makes this a little confusing, but it's basically:
... -d 'whatever'"$thevar"'whatever' "https..."
Now it should be working, and you could now shell script it, separating those long strings out into variables, and pulling in, say, a $1 arg to make it easy to ping a certain room with messages from your servers. I.e. something like:
> matrixlog "did a yum update"
Recommend
-
85
README.md HTTPie for curl If you like the interface of HTTPie but miss the features of curl, curl-httpie is what you are sear...
-
86
What is curl? curl is a program that is included in your Mac OSX distribution used for transferring data from or to a server. It uses many supported protocols (HTTP, HTTPS, FTP, SMTP and more).
-
64
-
74
扫描关注公众号(yudadanwx,虞大胆的叽叽喳喳),了解我的最新文章。 Curl 可以说是非常流行的一个客户端网络请求工具,充分理解了 C...
-
95
-
193
扫描关注公众号(yudadanwx,虞大胆的叽叽喳喳),了解我的最新文章。 这篇文章是
-
97
-
6
Testing A Health Check Endpoint with Curl Sep 1, 2019 Given the move to auto scaling architectures front ended by load balancers, it is increasingly important to build into your application what is called a "h...
-
4
November 14, 2022 ...
-
4
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK