TargetApiSimulator is a simple ASP.NET Core API that accepts POST requests at the /api/target endpoint,
validates whether the incoming request body is valid JSON, and responds with the validation result.
This project demonstrates basic API creation and JSON validation, allowing users to simulate an endpoint and check if provided data follows the JSON format.
- Receives JSON POST requests
- Validates JSON payloads
- Returns success (
200 OK) or error (400 Bad Request) responses - Can be used for testing or as a target API for integration scenarios
- JSON validation
- Testing API endpoints
- Integration testing simulations
To start the API, simply run the application using the provided TargetApiSimulator.sln solution file.
POST /api/target
Description:
Validates if the request body contains a valid JSON.
Returns:
200 OKwith the responsetrueif the JSON is valid.400 Bad Requestwith an error message if the request body is not valid JSON.
Example request:
POST /api/target
Content-Type: application/json
{
"key": "value"
}
Example response (for valid JSON):
200 OK
true
Example response (for invalid JSON):
400 Bad Request
{
"ErrorMessage": "This is not JSON"
}
The IsValidJson method verifies if the request body is valid JSON by attempting to parse the string.
If the string cannot be parsed, the API will return a 400 Bad Request status with an error message.
You can get latest release and run it without launching solution file:

Once the solution files are downloaded, you can run it in the console. Any messages you receive will be displayed there.
You can containerize the TargetApiSimulator using the provided Dockerfile. Below is a sample Docker command to build and run the container.
To build the Docker image:
docker build -t targetapisimulator .To run the container:
docker run -p 5000:80 targetapisimulatorAfter the container starts, you can send requests to the API at http://localhost:5000/api/target.
Run the API inside a Docker container:
docker run -d -p 5000:80 targetapisimulatorYou can then send POST requests to the API using tools like curl or Postman.
This is a simple project intended for testing and demonstration purposes. It is not designed for production use. Please review and adapt the solution to your needs.