{"id":23395926,"url":"https://github.com/ghindea/http-communication-with-web-server","last_synced_at":"2025-09-06T06:40:00.791Z","repository":{"id":249645462,"uuid":"832099354","full_name":"Ghindea/HTTP-communication-with-web-server","owner":"Ghindea","description":"C++ Client app for HTTP communication with web server","archived":false,"fork":false,"pushed_at":"2024-07-22T11:00:51.000Z","size":138,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-14T13:38:58.728Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ghindea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-22T10:56:29.000Z","updated_at":"2024-07-22T11:01:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"dd3eb9aa-fb47-415c-8eda-29e8124d6a75","html_url":"https://github.com/Ghindea/HTTP-communication-with-web-server","commit_stats":null,"previous_names":["ghindea/http-communication-with-web-server"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ghindea%2FHTTP-communication-with-web-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ghindea%2FHTTP-communication-with-web-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ghindea%2FHTTP-communication-with-web-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ghindea%2FHTTP-communication-with-web-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ghindea","download_url":"https://codeload.github.com/Ghindea/HTTP-communication-with-web-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247888568,"owners_count":21013002,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-22T07:19:35.889Z","updated_at":"2025-04-08T17:19:41.610Z","avatar_url":"https://github.com/Ghindea.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Client app for HTTP communication with web server\r\n\r\nmade by: _Daniel Ghindea - 325CB_\r\n\r\n---\r\n\r\n### Dependencies\r\nThe program uses [nlohman/json](#json-parsing) library for JSON parsing.\r\n\r\nAlso, during development, the server at 34.246.184.49 was used to test communications, but it may currently be down.\r\n\r\n## MAKEFILE\r\n```bash\r\n    $ make run   # compile \u0026 run executable\r\n    $ make clean # cleanup\r\n```\r\n\r\n## Description\r\nClient app receives commands from standard input to interact with the web server. When a command\r\nis given, the program sends an HTTP request to the server \u0026 receives a response that is displayed.\r\n\r\nList of commands:\r\n- `register` - create a user account\r\n- `login`\r\n- `enter_library` - request access to the library\r\n- `get_books` - list a summary of all available books\r\n- `get_book` - list the details of a specific book\r\n- `add_book`\r\n- `delete_book`\r\n- `logout`\r\n- `exit` - end the execution\r\n\r\n### About\r\nProgram's functionalities are encapsulated in `client_http` class. Its arguments store client's `username`, `password` and `access token` and the principal method, `run_client()`,\r\nimplements an infinite loop where commands are read from standard input. Depending on the given input, additional data may be read and the method that corresponds to the action is called.\r\n\r\nThe functionalities for HTTP communication are implemented in `http_communication` class. It contains methods that compute `GET`, `POST` \u0026 `DELETE` requests and methods that realize the communication with the server through sockets.\r\n\r\nEvery action-related method work as it follows:\r\n- a string that represents the `message` request is formed according to the desired action\r\n- `send_to_server()` method is called with `message` as parameter\r\n- the returned string is interpreted; if the HTTP request was successful a success message or the returned data is displayed, otherwise an error message is displayed.\r\n\r\n\r\n### HTTP protocol\r\nHTTP request protocol is implemented with the help of sockets. To request, update and delete data from the server `GET`, `POST` \u0026 `DELETE` methods are used.\r\n- **register**: \r\n```py\r\nPOST /api/v1/tema/auth/register HTTP/1.1\r\nHost: 34.246.184.49\r\nContent-Type: application/json\r\nContent-Length: 38\r\n\r\n{\"username\":\"README\",\"password\":\"123\"}\r\n```\r\n\r\n- **login**:\r\n```py\r\nPOST /api/v1/tema/auth/login HTTP/1.1\r\nHost: 34.246.184.49\r\nContent-Type: application/json\r\nContent-Length: 38\r\n\r\n{\"username\":\"README\",\"password\":\"123\"}\r\n```\r\nHTTP response from server contains a session cookie that is stored in its corresponding attribute while the program runs.\r\n\r\n- **access**: \r\n```py\r\nGET /api/v1/tema/library/access HTTP/1.1\r\nHost: 34.246.184.49\r\nCookie: connect.sid=s%3AuAHUePO_ndfL6jfbpalzR7BEq07jxzIi.ucbnWjM6xVHLoy3QVoHPPVtZJYzfvs9Mqqw7zyTkXT8; Path=/; HttpOnly\r\n```\r\nHTTP response from server contains an access token that is stored in its corresponding attribute.\r\n\r\n- **other commands** are implemented similarly by including the access token in the header `\"Authorization: Bearer \" + access_token` \r\n\r\n*check `define.h` for macros\r\n*`get_JSON_credentials()` returns the credentials of the user as a string in JSON format (`{\"username\":\"gigi\",\"password\":\"1234\"}`)\r\n\r\n### JSON parsing\r\nThe program uses [nlohman/json](https://github.com/nlohmann/json) library for JSON parsing. The library is included in the project as a header file.\r\nIt was used to parse the JSON response from the server and extract the necessary information.\r\n\r\n```c++\r\n    rc = req.receive_from_server();\r\n    json token = json::parse(strstr(rc, \"{\"));\r\n\r\n    if (!token[\"token\"].empty()) {\r\n        access_token = token[\"token\"];\r\n        MSG(true, \"Access granted\");\r\n    } else {\r\n        MSG(false, \"Access denied\");\r\n    }\r\n```\r\n\r\n\r\n### Checker\r\nTo run the checker run this command\r\n```bash\r\n    python3 checker/checker.py --script ALL ./client  # run all tests\r\n    python3 checker/checker.py --help     # for more details\r\n```\r\n\r\n### Bibliography \u0026 tools\r\n- [lab](https://pcom.pages.upb.ro/labs/lab9/http.html)\r\n- [postman](https://www.postman.com/)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghindea%2Fhttp-communication-with-web-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghindea%2Fhttp-communication-with-web-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghindea%2Fhttp-communication-with-web-server/lists"}