Giter VIP home page Giter VIP logo

http-books-client's Introduction

Books REST API HTTP Client, C++

CIORNEI ALEXANDRU-ȘTEFAN, 324CD

Program flow

The program loop reads input from the console, using a command factory to initialize the right command object to be executed. Based on the command, the program uses the overloaded promptInput() method to ask the user for more input, passing an InputValidator object to the method if necessary. An HTTPRequest object is instantiated based on the action's corresponding method, path, and JSON content if necessary, which is then sent to the server.

The nlohmann/json library was chosen to help with JSON data handling for its trivial integration (a single .hpp included header file) and intuitive syntax (looping through JSON arrays like a normal C++ array using an enhanced for, accessing JSON object properties like an associative array: object["member"]).

The Client's sendToServer() method responds with a HTTPResponse object which is then interpreted for errors based on the status code, displaying a success or error message accordingly. A new socket is opened before sending a new request and then closed after receiving the response from the server. The cookies and JWT for the library access are stored in the SessionData object which is modeled by the Singleton pattern, making them available globally.

Project Structure

  • /src: contains the class implementations
  • /include: contains the header files with the class declarations and the JSON library
  • main.cpp: the main program loop, exits the loop if it catches an exited() exception, thrown in the exit command
  • ConsoleCommands.cpp: the command objects which handle the various actions, constructing and sending HTTP requests and displaying responses from the server
  • HTTPRequest.cpp: request object which exposes a method to easily construct the request string buffer to be sent to the server
  • HTTPResponse.cpp: response object which is automatically constructed from a response string buffer, encapsulating the response status code/text and data
  • HTTPClient.cpp: contains the methods for sending an HTTP request and receiving an HTTP response with TCP sockets
  • InputValidator.cpp: validator classes for user input validation, such as NoSpacesValidator or NumberValidator
  • SessionData.cpp: the session data singleton, fetched whenever needed

http-books-client's People

Contributors

alexciornei22 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.