NetLinx HTTP Client
PhreaK
Posts: 966
As we are yet to get any support from inbuilt NetLinx libraries for working with HTTP, here's a little tool for those who may not want to push all of these comms through Duet.
https://github.com/ciasia/http
The http lib is a minimal, performant HTTP client for working with web services natively from NetLinx. Methods are provided for GET, HEAD, PUT, POST, PATCH and DELETE requests over HTTP/1.1. In it's vanilla form it will support up to 15 simultaneous requests however this can be expanded to match your requirements. Callbacks (following the RMS SDK callback pattern) are provided for all responses and errors, including communication timeouts and socket errors. These callbacks are also given a pre-parsed response with everything neatly separated into a structure containing the response code, headers and body. More info in the readme.
For working with JSON data within the requests or PUT/POST/PATCH bodies you may also find the jsmn library and json-builder include of use.
Feel free to fork, improve and optimise at will. If you come across any issues, but don't have the time to build out a fix, it would be awesome if you could log the issue on GitHub so someone from the community can fix it up for all.
https://github.com/ciasia/http
The http lib is a minimal, performant HTTP client for working with web services natively from NetLinx. Methods are provided for GET, HEAD, PUT, POST, PATCH and DELETE requests over HTTP/1.1. In it's vanilla form it will support up to 15 simultaneous requests however this can be expanded to match your requirements. Callbacks (following the RMS SDK callback pattern) are provided for all responses and errors, including communication timeouts and socket errors. These callbacks are also given a pre-parsed response with everything neatly separated into a structure containing the response code, headers and body. More info in the readme.
For working with JSON data within the requests or PUT/POST/PATCH bodies you may also find the jsmn library and json-builder include of use.
Feel free to fork, improve and optimise at will. If you come across any issues, but don't have the time to build out a fix, it would be awesome if you could log the issue on GitHub so someone from the community can fix it up for all.
1
Comments
It's in the Git repo listed in the init of the thread
I just saw a description of the functions, not a fully functioning example.
Forgive my ignorance but how can I push back into your repository?
Do I make a pull request or something like that?
Cheers
Mush
P.S. thanks in advance.
Edit: Never mind, fixed it! Thanks again for the great chunk of code [USER="6496"]PhreaK[/USER]
Just for the benefit of anyone else reading along, there is not currently any request buffering implemented. You'll see that message logged if you attempt to exceed the number of simultaneous requests allowed. This can however be changed to suit your application (e.g. lots of requests, slow web server etc). Under normal conditions requests will timeout 10 seconds after they are executed. If you are getting this repeatedly, it means you have a socket stuck open and something has gone wrong so let me know.
After separating the two commands to a push and release, that seemed to do the trick.
Although, this solution doesn't sound right to me...but I may be missing something.
The other possibility is it had something to do with the network I was on, as changes were made in the time between the problem happening and the problem disappearing.
But, if my understanding of the code is correct, I get that error message due to a lack of RequestID...what I don't understand is if that RequestID is generated by the AXI or by the server.
Apologies for my ignorance...I wish I had a better explanation!
I was just going to dive in and try things out. OK, I haven't got anything (http wise) to try it out with, but hey ho.