Skip to content

A HTTP client that communicates with a RESTful server using JSON. It processes user commands to send requests and handles both success and error responses. The implementation supports common HTTP methods like GET, POST, PUT and DELETE.

catalinamanolache/RESTful-HTTP-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RESTful HTTP Client

Description

This solution implements an HTTP client that accepts user commands and communicates with a REST architecture server. The client sends HTTP requests to the server and handles responses through success or error messages. Data exchange is performed in JSON format.

Solution Components

The implementation builds upon the 09. HTTP Protocol Communication Protocols laboratory solution, which already contained some HTTP request implementations and server interaction mechanisms. My implemented commands are located in commands.cpp, with helper functions added to helpers.cpp.

JSON Parsing Library

I used the json.hpp and json_fwd.hpp files from the recommended C++ library, nlohmann, to work with data in JSON format. I also used the json::parse and json::dump functions to transform strings into JSON and vice versa, as well as the [] operator to access values within JSON objects.

Commands Implementation

Authentication Commands

  • login_admin / login_user - Obtain credentials from keyboard, check for spaces, check if user isn't already authenticated by validating cookies and send authentication request. On 200 response, save cookies and set admin flag (for admin login). On 403, credentials are incorrect.

  • logout_admin / logout_user - Verify authentication status and send logout request. On 200 response, clear cookies/JWT and reset admin flag (for admin logout).

User Management Commands (Admin Only)

All user management commands require admin authentication.

  • add_user - Obtain and validate credentials and send user creation request. On 201 response, save cookies.

  • get_users - Send request to retrieve user list. On 200 response, display username and password for each user.

  • delete_user - Obtain and validate username and send deletion request. On 200 response, save cookies. On 404, user was not found.

Library Access

  • get_access - Verify admin status and send access request. On 200 response, save cookies and JWT token.

Movie Management

All movie operations require library access.

  • add_movie - Obtain and validate movie information and send data as JSON. On 201 response, save cookies.

  • get_movies - Retrieve and display movie list with ID and title for each entry.

  • get_movie - Obtain movie ID, complete path with ID and send request. On 200 response, display movie details (title, year, description, rating). On 404, movie not found.

  • update_movie - Obtain movie ID and information, send JSON with updated path. On 404 if movie not found.

  • delete_movie - Obtain movie ID, complete path with ID for deletion. Returns 404 if movie not found.

Collection Management

All collection operations require library access.

  • add_collection - Obtain collection information (title, number of movies, movie IDs) and send as JSON. On 201 response, save cookies and add each movie using add_movie_to_collection. Display success only if all movies were added successfully, otherwise display error.

  • add_movie_to_collection - This function can be called both from within add_collection and from client.cpp as a standalone command, indicated by the is_standalone flag.

    • When called from add_collection, it receives movie and collection IDs as parameters, does not read them from keyboard, and does not check library access since this was already done in add_collection. It returns success or error codes instead of displaying error messages.
    • When called from client.cpp, it reads movie and collection IDs from keyboard, checks library access, and if access is granted, sends the request to the server with movie information in JSON format. If the response is 201, it saves cookies and displays a success message. If the response is 404, it indicates that the collection was not found by the ID entered by the user, or the user does not have access to the collection. If the response is 400, it indicates that the movie already exists in the collection. For other response codes, it displays the corresponding message.
  • delete_movie_from_collection - Obtain movie and collection IDs, complete path with both IDs for removal.

  • get_collections - Retrieve and display collection list with ID and title for each entry.

  • get_collection - Obtain and validate collection ID and display collection information including owner, title and movie details (ID and title for each film).

  • delete_collection - Obtain collection ID and send deletion request with ID in path.

About

A HTTP client that communicates with a RESTful server using JSON. It processes user commands to send requests and handles both success and error responses. The implementation supports common HTTP methods like GET, POST, PUT and DELETE.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages