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

Feature - Add REST API using Typescript #117

Open
fandikaikhsan opened this issue Mar 28, 2024 · 0 comments
Open

Feature - Add REST API using Typescript #117

fandikaikhsan opened this issue Mar 28, 2024 · 0 comments

Comments

@fandikaikhsan
Copy link

fandikaikhsan commented Mar 28, 2024

Is your feature request related to a problem? Please describe

Hi! I want to express my interest in contributing to the One Buy Away project by initiate the REST API client for OBA using Typescript as it said needed in this page..

Please note that this issue may not be a part of the onebusaway-docs' issues. I opened the issue here because I haven't seen any repos related to REST API development, and this repo is the most active with recent updates. I will close the issue if there is a better place to discuss this matter.

Describe the solution you'd like

Project Idea

The vision for this project is to create a comprehensive REST API using TypeScript, with a strong emphasis on type safety and maintainability. I propose to start developing the api using route-controller-service structure with expressJS.

The project structure will look like this:

onebusaway-ts-rest/
├── src/
|   ├── configs/
│   ├── controllers/
│   ├── dtos/
│   ├── interfaces/
│   ├── models/
│   ├── routes/
│   ├── services/
│   └── index.ts
├── tests/
│   ├── ...
├── docs/
│   ├── swagger/
│   └── index.html
├── node_modules/
├── .gitignore
├── package.json
├── tsconfig.json
└── README.md

I will follow the current response pattern using code, current_time, and data in response body.

{
  "code": 200,
  "currentTime": 1710977677779,
  "data": {
   ...
}

To ensure that only valid data is accepted by the API, I will implement Data Transfer Objects (DTOs) using the Class Validator library. DTOs act as a contract between the client and server, defining the structure and validation rules for incoming data. By validating input at the DTO level, we can prevent invalid data from being processed, thereby enhancing security and reliability.

For fetching data from databases (If OBA using relational db) I propose to use Prisma as the ORM, we can streamline database operations, enhance data modeling, and ensure consistency across data interactions.

To ensure code quality and consistency, I will incorporate ESLint and Prettier into the development workflow. These tools will enforce coding standards, detect potential errors, and automatically format code, contributing to a more maintainable and professional codebase.

I will implement testing using Jest, a popular testing framework for JS and TS. With Jest, we can create unit tests to ensure the functionality of individual components and integration tests to validate the interactions between different parts of the application.

Library docs list:

Library Name Docs
ExpressJS https://expressjs.com/
Prisma https://www.prisma.io/docs
Class Validator https://github.com/typestack/class-validator
Swagger https://swagger.io/solutions/api-documentation/
Eslint https://eslint.org/
Jest https://jestjs.io/

Additional Ideas

To facilitate ease of use for developers, I propose integrating Swagger for API documentation. This will provide a comprehensive reference for endpoints, request/response payloads, and example usage scenarios, streamlining the onboarding process for new contributor while waiting the docs team completed the integration process.

Note

I really loved to discuss about this project @aaronbrethorst I also have several questions releated to the project.

  • Is there any API Spec docs as a brief to the api requirement. Including the header and all the response cases for each route? Or this page could be our references? https://developer.onebusaway.org/api/where
  • How api fetch the data? Do the api directly fetch to the data like using ORM to database? If yes, is there any dump data example for testing purposes?

Describe alternatives you've considered

No response

Additional context

If necessary, I would love to provide samples of my code using the proposed patterns. I will deploy the project to my VPS for testing and demonstration purposes.

Are you working on this?

Yes

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

No branches or pull requests

1 participant