Tag: javascript

  • Correctly Handle JavaScript Error Messages

    Correctly Handle JavaScript Error Messages

    In the post about REST API Filtering we have getFilterBy method in BaseRepository that calls getSequelizeWhereClause function and returns result. The call is wrapped up in try…catch block, so when an error is thrown, it gets transformed into an API error and get re-thrown. The message from the original error is assigned to the API…

  • Advanced Filtering in REST API

    Advanced Filtering in REST API

    In this article we will look at how to implement advanced filtering in REST API when a GET request a list of results. In our API project that will be GET /v1/travels and GET /v1/tours endpoints. Although setup for filtering is similar to sorting, the implementation is a bit more complex. First we are going…

  • Sequelize Seeders: Generating Test Data

    In this article we will look at how to use Sequelize seeders to seed the database with test data and use Faker library to generate the test data. We will continue working in the project travel-api-db-migration-service we created in the video Sequelize Migrations. Please, watch that video if you would like to see how the…

  • REST API Delete Resource

    REST API Delete Resource

    In this article we will look at REST API Delete operation. Compared to Create and Update, Delete operation is fairly easy and straightforward. REST API Delete Implementation Below, we will outline the basic steps of Delete operation implementation. Please, watch our video for more in depth explanation of this concept. Route and Controller In routes/v1/travels…

  • REST API Update Resource

    REST API Update Resource

    In the previous article REST API Request Validation we looked at how to create a resource using POST request and Joi validation. In this article we will look at how to use REST API Update operation to modify a resource. We will also be using Joi validation to ensure security and consistency. Compared to creation,…

  • REST API Request Validation

    In this article we will look at how to validate POST requests to the REST API using Joi library. Joi lets you describe your data using a simple, intuitive, and readable language. We will also look at how to turn Joi errors into 422 Validation Error API responses. Describe REST API Request Shema with Joi…

  • HMAC Validation

    In this HMAC Validation tutorial, we will define what HMAC is, its benefits, and implement HMAC validation as a middleware in an API project. HMAC stands for hash-based message authentication code. An HMAC algorithm works by hashing a message along with a secret key. The resulting hash is called a signature or digest. The message…

  • Repository Pattern in JavaScript

    The Repository Pattern is a structural pattern that abstracts and centralizes data access operations, providing a consistent and simplified interface for the application to interact with data sources. In essence, the Repository Pattern acts as a mediator or a middleman between the application’s business logic and the data storage, shielding the rest of the code…

  • Environment Variables in JavaScript

    Environment variables in JavaScript are a set of key-value pairs that can be used to store data outside of the JavaScript code. This data can be anything from API keys to database credentials. Environment variables are often used to keep sensitive data secret, as they are not stored in the code itself. We can import…

  • Automatically Log or Append Data to Express Response

    Sometimes you need to log Express response in order to see what your application responded with. Doing it for each route can be tedious. A better approach is to use a middleware. The middleware also gives you the flexibility to choose responses from which routes to log. When you have access to your response in…