Skip to content

kellymoreira/Timestamp-Microservice

Repository files navigation

Clock

Timestamp Microservice 🗓️

This project is a RESTful API for date manipulation.

Project Made at December 2023 Code Size in bytes Main Language Project Status

About | Technologies | Usage | Resources | Documentation | Feedbacks

📜 About

Designed to provide a RESTful API that responds to requests made at specific endpoints related to date manipulation for study purposes. It's the first project from freeCodeCamp. Tap here to see the instructions
It supports three main functionalities:

Date Conversion Endpoint:

  • Requests to /api/:date? return a JSON object.
  • Valid date input returns unix timestamp (in milliseconds) and utc representation.
  • Invalid date input results in { error: "Invalid Date" } response.

Date Parsing:

  • Capable of handling dates parsed by new Date(date_string).

Default Behavior:

  • An empty date parameter defaults to the current time.
  • Returns JSON object with unix timestamp and utc representation of the current time.

🗃️ Technologies

  • Node.js
  • Express.js
  • CSS
  • HTML

🏨 Example Usage (Hypothetical Situation)

Booking System for Appointments or Reservations:

Consider a scenario where users choose a date and time for an appointment. The API can assist in converting and storing these timestamps. When a user selects a date and time for an appointment, the API facilitates the conversion and storage of these timestamps in a standardized format. This ensures smooth communication between different components of the system.

Request:

Make a GET request to /api/appointment with the date parameter:

GET /api/appointment?date=1706544000000

Response:

The API returns a JSON object with the Unix timestamp and UTC string:

{
 "unix": 1706544000000,
 "utc": "Thu, 29 Jun 2023 00:00:00 GMT"
}

How It Works:

  • The code captures the date parameter from the URL (req.params.date) and checks if it's a valid Unix timestamp.
  • If it is, the code converts it to a standard format with Unix timestamp and UTC string.
  • If it's not a valid Unix timestamp, the code attempts to parse it as a date string and provides the corresponding Unix timestamp and UTC string if successful, or an error message if the parsing fails.

📋 Documentation

I used Swagger for API documentation, although the project itself doesn't contain many APIs, the purpose of this documentation is to allow manual testing.

To interact with the project, follow these steps:

  1. Install the necessary dependencies. This can be done using the command:
$ npm install
  1. Generate the documentation at project startup. This is useful if you want to view the current state of the API documentation without starting the project. Use the command:
$ npm run start-gendoc
  1. Start the project without generating the documentation. This is typically faster than the previous step, especially if you don't need to view the API documentation right away. Use the command:
$ npm start

Once the project has started, you can access the documentation at: http://localhost:3001/api-docs/

📨 Feedbacks

I'm a Junior, and I really would like to hear in case there are any tips, corrections, suggestions, or comments about this little project. Your feedback is highly valued, and it helps me improve and learn!

💡 Resources