You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Develop a backend endpoint to handle requests for newsletter subscriptions. The endpoint will accept an email address, validate and sanitize it, and then handle both successful and failed validations appropriately. If the email passes validation, it will be stored in the database and a 'success' response will be sent to the client. If validation fails, an error message will be returned.
Acceptance Criteria
Accepts and validates User's email.
Persist the data to the database.
Return the appropriate response and status code
Requirements
Implement API endpoint with data validation and sanitization
Set up database integration and secure storage
Integrate email service for confirmation messages
Expected Outcome
The user input data should be successfully sent to the backend, or the user will receive an error message if unsuccessful
Status code
201: Email was successfully stored.
400: Invalid email address.
401: Email already exist.
500: A server error occurred.
Endpoint
[POST] /api/v1/pages/newsletter
Requests:
headers:
content-type: application/json
{
"email": "string"
}
Responses:
Successful response
{
"message": "string",
"success": true,
"status_code": int
}
Error response
{
"message": "string",
"success": false,
"status_code": int
}
Database design
schema
Table name: subscribers_table
id:
constraints: string(uuid), unique, primary-key, not null
email:
constraints: string, unique, not null, length(150)
createdAt:
constraints: string, date timestamp
Testing
Unit Tests
The systems should have unit tests covering:
Validates User's email and check for duplicate emails.
Ensure data is saved correctly to the database.
Test that the appropriate response and status code is returned
The text was updated successfully, but these errors were encountered:
Description
Develop a backend endpoint to handle requests for newsletter subscriptions. The endpoint will accept an email address, validate and sanitize it, and then handle both successful and failed validations appropriately. If the email passes validation, it will be stored in the database and a 'success' response will be sent to the client. If validation fails, an error message will be returned.
Acceptance Criteria
Requirements
Expected Outcome
Status code
Endpoint
[POST] /api/v1/pages/newsletter
Requests:
headers:
Responses:
Successful response
Error response
Database design
schema
Table name: subscribers_table
id:
email:
createdAt:
Testing
The systems should have unit tests covering:
The text was updated successfully, but these errors were encountered: