Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize on Responses #25

Open
Tracked by #34
human058382928 opened this issue Dec 19, 2024 · 2 comments
Open
Tracked by #34

Standardize on Responses #25

human058382928 opened this issue Dec 19, 2024 · 2 comments

Comments

@human058382928
Copy link

Make sure that the responses are standardized. Right now some return in a wrapper like

{"status": "success", "data": object } 

and some are just the

object

We just need one way to do them all. I would say do them all wrapped that way incase we need to do pagination you can add that metadata in the wrapper like .

{"status": "success", "page": 1, "total": 500, "data": object}

Technically i don't need the status field that can be determined through http codes.

@human058382928
Copy link
Author

If its not a 200 then we can standardize on body always being

{"error": "somemessagehere"}

@whoabuddy whoabuddy mentioned this issue Dec 20, 2024
8 tasks
@whoabuddy
Copy link
Contributor

whoabuddy commented Dec 20, 2024

This was the template I used while updating each endpoint, should all be fixed in #34 now


1. Successful Responses (Status Codes 200-299)

When Returning Data

createApiResponse({
	message: 'A clear description of what succeeded',
	data: { theActualData },
});

When Returning Message Only

createApiResponse({
	message: 'A clear description of what succeeded',
});

2. Error Responses (Status Codes 300+)

Use a direct string message:

createApiResponse('A clear description of what went wrong', errorStatusCode);

3. Specific Patterns

  • Always include a descriptive message for successful operations
  • Keep error messages concise and descriptive
  • Use consistent status codes for similar types of errors
  • Data should be structured as an object when including additional information

4. Implementation Examples

Success with Data

return createApiResponse({
	message: 'Successfully retrieved crews',
	data: { crews },
});

Success with Message Only

return createApiResponse({
	message: `Successfully deleted ${key}`,
});

Error Response

return createApiResponse('Missing required parameter: address', 400);

Example Responses

Example Success Response:

{
	"success": true,
	"message": "Successfully retrieved crews",
	"data": { "object with data" }
}

Example Success Response (Message Only):

{
	"success": true,
	"message": "Successfully deleted crew"
}

Example Error Response:

{
	"success": false,
	"error": "Missing required parameter: address"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants