Reflecting on REST API best practices
Now, it’s time to reflect on what we’ve done so far. While coding, we may have forgotten a couple of best practices we already know from previous chapters. So, let’s go back and see where we didn’t do well and appreciate things we did well:
- Consistent and resource-oriented URL design:
- Best practice: REST APIs should have clear, logical, and resource-oriented URLs. Each URL should consistently represent a specific resource or collection of resources.
- Implementation in our API:
- Our user management API uses RESTful routes such as
/users
to access the user collection and/users/:id
for specific user operations - Here’s an example code snippet:
@Controller('users') export class UsersController { @Get() findAll() { /*...*/ } @Get(':id') findOne(@Param('id') id: string) { /*...*/ } // ...other methods }
- Our user management API uses RESTful routes such as
- Use of HTTP...