0% found this document useful (0 votes)
16 views3 pages

NodeJS Zip Pay User API Design

This document outlines requirements for building an API to manage Zip Pay users. The API needs to support creating, getting, and listing users, and creating accounts for users while adhering to business requirements. It should be implemented with TypeScript, persist data to a database, be properly documented, and follow best practices for REST API design.

Uploaded by

Ruben Araqelyan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

NodeJS Zip Pay User API Design

This document outlines requirements for building an API to manage Zip Pay users. The API needs to support creating, getting, and listing users, and creating accounts for users while adhering to business requirements. It should be implemented with TypeScript, persist data to a database, be properly documented, and follow best practices for REST API design.

Uploaded by

Ruben Araqelyan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Zip Candidate User API

Challenge: NodeJS
We have a fictitious scenario where we'd like to build an API to manage Zip Pay
users. We require the ability to create, get, and list users. Once we create users, we
need the ability for the user to create an account.

This should be implemented with an API and database.

Business Requirements
• Should not allow more than one user with the same email address
• Zip Pay allows credit for up to $1000, so if monthly salary - monthly expenses is less
than $1000 we should not create an account for the user and return an error

Tech Requirements
• Use TypeScript
• Database: Users and Accounts should persist to database of your
choice See Supporting Services below
• Documentation: Update [Link] with information you'd give to other
members of your team about how to start and run the solution, and anything else
you'd like us to know

Supporting Services
To assist with your submission and to save you time in downloading and installing
software, we've included a [Link] with boilerplate configuration for a few
popular database options (MSSQL, PostgresQL, and MySQL). Choose one and
remove the other two (or substitute) based on your preference. Note that you only
need to have one database, you don't need to use all of them.

If your submission calls for other supporting services, feel free to add as necessary
to your docker-compose config.
API Requirements
1. The following Endpoints are required:
• Create user
• Fields to be provided and persist
• Name
• Email Address (Must be unique)
• Monthly Salary (Must be a positive number - for simplicity,
pretend there is no such thing as income tax)
• Monthly Expenses (Must be a positive number)
• List users
• Get user
• Create an account
• Given a user, create an account
• Should take into account the business requirements above
• Up to you to decide the appropriate fields to persist here
• List Accounts
2. Should be robust and include relevant response codes for different scenarios
3. No need to implement any kind of auth for this test

Definition of Done
This solution should be what you consider to be production ready, so think carefully
about what you want to include.

1. Code should be self-documented, use comments liberally. We want to see


how well you communicate thru your code.
2. Proper exception handling for REST endpoints with correct standard error /
status codes being returned from the API layer.
3. We would like to see how well you separate code and entities at different
layers, like, API, Biz Logic and Repository layers. Use a clean folder structure
to reflect various layers.
4. We would like to see what design patterns and/or libraries you want to use, if
applicable.
5. Should have unit test cases as well as some integration test. Use mocked DB
objects for unit tests.
6. [Link] should provide instructions to run and test your code. Also
document your APIs for other developers who are going to use your APIs. We
would like to see how well you communicate thru your documents.
7. Boiler plate code contains [Link] file. Update and use it to spin
up database and the service you develop.
8. Follow best practices, like, logging, error handling.

NOTE: You may share your code using Github (preferred - mail us the link to your
code) or as a zip file (mail us the zip file).

Points to take care for REST endpoints

1. Use Nouns for Resource Identification. Bad Practice: Do not use verbs
2. Use Plural Nouns to Name a Resource
3. Use Proper HTTP Headers for Serialization Formats
4. Use Sub-Resources for Relations
5. Use Proper HTTP Methods
6. HTTP Response Status Codes
7. Field Name Casing Convention
8. Restful API Versioning
9. Refer : [Link]
design/

Common questions

Powered by AI

The Docker setup, facilitated through a docker-compose.yml file, simplifies running and testing the Zip Pay API by allowing developers to create an isolated and consistent development environment. It abstracts away the complexity of installing and configuring environments on different machines. By specifying the services and configurations needed, the setup ensures that the API and its database dependencies can be easily spun up or down, thus encouraging more robust testing and development interactions since developers can easily replicate the production environment locally .

The docker-compose.yml file plays a crucial role in facilitating the development of the Zip Pay API by managing dependencies and simplifying the setup of the development environment. It allows developers to define and run multi-container Docker applications, ensuring consistency across environments and simplifying configurations for databases like MSSQL, PostgresQL, or MySQL. This file enables quick provisioning of these databases without manual installations, thus accelerating development workflows and promoting ease of testing in isolated environments .

Implementing proper exception handling and error status codes in the REST endpoints of the Zip Pay API requires several considerations. Each API endpoint must be designed to catch and handle expected and unexpected exceptions to prevent crashes and provide meaningful error messages. This involves using try-catch blocks, logging errors for debugging, and returning appropriate HTTP status codes (e.g., 400 for bad requests, 404 for resource not found, or 500 for server errors) to inform clients of the error type. It is critical to design these responses to be consistent and informative, aiding in client-side troubleshooting and enhancing the API's reliability .

Updating the Developers.md file is significant in a collaborative Zip Pay API development environment because it serves as a central resource for onboarding new developers and synchronizing the team. This documentation should include clear instructions on setting up the environment, running tests, deploying the API, and using the endpoints. Comprehensive documentation ensures that every team member has access to the same information, reducing errors and misunderstandings. It facilitates smooth transitions between tasks and prevents knowledge silos, thereby aligning the team's efforts with best practices and project objectives .

The unique email constraint in the Zip Pay API's user management system should be implemented at both the database and API logic levels for complete enforcement. At the database level, a unique index should be created on the email column within the Users table to automatically prevent duplicate entries. In the API logic, before attempting to insert a new user, a check should be made to see if the email already exists, allowing the API to return a meaningful error message if a duplicate is attempted. This dual approach ensures consistency and reliability in enforcing the uniqueness constraint .

Unit and integration tests are critical in ensuring the reliability of the Zip Pay API as they validate different parts of the application. Unit tests focus on individual components and functions in isolation to check for correct behavior and handle edge cases. Integration tests ensure that different parts of the application work together as expected, particularly checking interactions with the database and verifying endpoint behaviors. These tests help catch bugs early, ensure components work as designed, and provide a safety net for future code changes, thus contributing significantly to the API's overall stability and quality .

The use of TypeScript in the Zip Pay API enhances robustness and maintainability by providing static type-checking, which helps catch errors early in the development process and improves code quality. TypeScript's features such as interfaces and types can contribute to clearer and more self-documented code, making it easier for developers to understand the codebase and maintain it over time. Additionally, TypeScript's compatibility with JavaScript and its extensive tooling support further aid in creating an efficient development environment .

The core business requirements for the Zip Pay API involve ensuring each user has a unique email address and that a user can only have an account if their disposable income (monthly salary minus monthly expenses) is at least $1000 . These requirements influence the API architecture by necessitating checks during user creation and account creation operations, ensuring database constraints for email uniqueness, and validating financial criteria before account creation is allowed. This implies the need for robust error handling and validations at the business logic layer, as well as appropriate database integrations to enforce these rules .

The architecture of the Zip Pay API should utilize separation of concerns by distinctly segmenting the code into layers such as API, Business Logic, and Repository. The API layer handles incoming requests and outgoing responses, the Business Logic layer encapsulates the core functionalities including business rules and validations, and the Repository layer interfaces with the database. This separation supports better code manageability, reusability, and scalability, allowing developers to modify one layer without affecting the others extensively, thus adhering to best practices in clean architecture .

The proper use of HTTP methods and status codes significantly impacts the effectiveness of the Zip Pay API by ensuring that the API adheres to RESTful principles and provides clear communication of actions and their outcomes to API consumers. Using correct HTTP methods (e.g., GET for retrieving, POST for creating) ensures that the API's functionalities are semantic, and using appropriate status codes enables clients to interpret responses accurately (e.g., 200 for success, 400 for bad request). This consistency simplifies client implementation and debugging, enhancing user experience and the API's reliability .

You might also like