This documentation provides an overview of a Delphi application that implements CRUD operations using MongoDB as the backend database. The application includes a REST API built with HORSE, a popular Delphi web framework. Below, you'll find information on how to set up, run, and use this application.
The Delphi with MongoDB CRUD application is designed to perform CRUD operations (Create, Read, Update, Delete) on a MongoDB database using a RESTful API. The application includes a Delphi form for configuring the API server settings.
Before you get started with the Delphi with MongoDB CRUD application, make sure you have the following prerequisites in place:
- Delphi IDE installed on your system.
- MongoDB server running and accessible.
- HORSE library for Delphi installed.
-
Clone this repository to your local machine.
-
Open the Delphi project using your Delphi IDE.
-
Inside the project, locate the "Form" designed for the application's settings.
-
In the form, you will find a field to specify the port on which the API server will run. You can also find a button to start and stop the server.
-
Set the desired port for the API server.
-
Click the "Start Server" button to activate the API server. You will see server logs indicating that the server has started successfully.
-
Once the server is running, you can proceed to use the API endpoints for CRUD operations.
The API provides the following CRUD operations for managing data in the MongoDB database.
- Description: Retrieve data from the database.
- Endpoint:
/api/data - Usage: Simply make a GET request to this endpoint to retrieve data. No JSON payload is required.
- Description: Insert data into the database.
- Endpoint:
/api/data - Request Body: JSON payload with data to be inserted. The JSON should follow the format below:
{
"cod_pessoa": "2",
"nome": "LUCIANO",
"idade": 25,
"sexo": "M",
"trabalho": "ESTUDANTE"
}- Description: Modify existing data in the database.
- Endpoint:
/api/data - Request Body: JSON payload with data to be modified. The JSON should follow the format below, including the cod_pessoa field to identify the record to be updated:
{
"cod_pessoa": "2",
"nome": "Luciano Arantes",
"idade": 24,
"sexo": "M",
"trabalho": "Estudante"
}- Description: Delete data from the database.
- Endpoint:
/api/data - Request Body: JSON payload with the cod_pessoa field to specify which record should be deleted. For example:
{
"cod_pessoa": "2"
}