A command-line HTTP client written in C that interacts with a movie library REST API. Supports two roles (admin and user), session-based authentication with cookies, and JWT-based authorization for library access.
Admin Operations
- login_admin = Authenticate as admin
- add_user = Create a new user account
- get_users = List all registered users
- delete_user = Remove a user by username
- logout_admin = End admin session
User Operations
- login = Authenticate as a user (requires admin username)
- get_access | Obtain a JWT token for library access
- logout | End user session
Movie Operations (require JWT)
- get_movies = List all movies
- get_movie = View details of a specific movie by ID
- add_movie = Add a new movie (title, year, description, rating)
- update_movie = Update an existing movie's details
- delete_movie = Remove a movie by ID
Collection Operations (require JWT)
- get_collections = List all user collections
- get_collection = View a collection's movies by ID
- add_collection = Create a collection with movies
- delete_collection = Remove a collection by ID
- add_movie_to_collection = Add a movie to an existing collection
- delete_movie_from_collection = Remove a movie from a collection
logout / exit
- Session cookie — stored after login, sent with every request
- JWT token — obtained via
get_access, required for all library endpoints - Both are cleared on logout
How It Works
- The client runs an interactive loop reading commands from stdin. For each command it:
- Validates the current session state (logged in? admin or user? has JWT?)
- Reads any required input (username, movie title, etc.)
- Builds an HTTP request (GET/POST/PUT/DELETE) with JSON body, cookies, and JWT header
- Opens a TCP connection to the server, sends the request, and parses the response
- Displays success/error messages based on the server response
- JSON serialization is handled using the Parson library.
Building & Running
- make
- ./client
Usage Example
- login_admin
- username=admin
- password=admin123
- SUCCESS: Admin autentificat cu succes
- add_user
- username=john
- password=pass123
- SUCCESS: Utilizator adaugat cu succes
- login
- admin_username=admin
- username=john
- password=pass123
- SUCCESS: User autentificat cu succes
- get_access
- SUCCESS: Token JWT primit
- add_movie
- title=Inception
- year=2010
- description=Mind-bending thriller by Nolan
- rating=9.1
- SUCCESS: Film adaugat cu succes
- get_movies
- SUCCESS: Lista filmelor
- #1 Inception
- exit