This project is a RESTful API for date manipulation.
About | Technologies | Usage | Resources | Documentation | Feedbacks
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:
- Requests to
/api/:date?
return a JSON object. - Valid date input returns
unix timestamp
(in milliseconds) andutc
representation. - Invalid date input results in
{ error: "Invalid Date" }
response.
- Capable of handling dates parsed by
new Date(date_string)
.
- An empty date parameter defaults to the current time.
- Returns JSON object with
unix timestamp
andutc
representation of the current time.
Node.js
Express.js
CSS
HTML
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.
Make a GET request to /api/appointment
with the date parameter:
GET /api/appointment?date=1706544000000
The API returns a JSON object with the Unix timestamp and UTC string:
{
"unix": 1706544000000,
"utc": "Thu, 29 Jun 2023 00:00:00 GMT"
}
- 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.
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:
- Install the necessary dependencies. This can be done using the command:
$ npm install
- 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
- 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/
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!