P
P
Pavel2015-12-25 13:49:06
Python
Pavel, 2015-12-25 13:49:06

Based on what is the best way to make a web service for sending, receiving data?

I keep a server at home with a couple of different services. I came up with the idea to write a small application for monitoring the state of the server, logging its state and managing services.
While all this is vaguely spinning in my head in the form of a web application packaged via xdk, which accesses the server to receive data (the data, as I imagine, will be parsed by a python through console commands like sensors and top, add them to the database) and manage services (roughly speaking send a command to python to stop, start, restart the service), or rather, run a pre-prepared bash script (otherwise remote launch of custom scripts seems wildly unsafe).
I wanted to ask, tell me, in which direction to dig at all? I just can’t even imagine how I will accept these requests. In the python documentation in the http.server.SimpleHTTPRequestHandler section there is a do_Get () method which, as I understand it, receives a string with parameters, parses and then the line is incomprehensible

If the request was mapped to a directory, the directory is checked for a file named index.html or index.htm

Those. should I have a dummy index.html when accessing the server http://servername.domain:port/mysuperutilitytachzfrom what ?
PS I did the processing of requests only in php, so when thinking about other languages, there is a slight panic and misunderstanding

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Peter, 2015-12-25
@rusbaron

You can take a ready-made web framework for python, for example: flask, django or another.
Next, you can fasten an API based on JSON RPC (description here ) to which you will access directly http://servername.domain:port/
Why JSON RPC?
Because there in the request you can specify the method to be called and set parameters for it.
You can call commands in batches.
You can also http://servername.domain:port/ make a regular page with authorization and transitions to the list of methods, the possibility of calling them, statistics, and then limiting your imagination.
The type of data returned will be set via Content-Type (json or web page)

V
Vladimir, 2015-12-25
@vintello

petermzg said everything correctly. get Flask and get creative. you have nowhere to grow, so that's enough with your head.
+ add Celery and Redis for task background

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question