code smartly

Programming tutorials with practical examples



Whilst many cool Javascript pagination packages out there, a lot of times what you might want is a simple function to handle pagination of certain items on a page. In such situations, installing a separate package to handle a simple pagination task might be overkill especially if you are particular and concerned about the portability and speed of execution of your code. In my opinion, installing a separate package to handle pagination of 200 items or less is definitely an overkill.

This guide is to help you understand the concept of pagination and how to implement a simple re-useable Javascript function that can be used to handle pagination of items of minimal sizes before being rendered on a page or returned as a response in an API request.

I will try to explain how you can easily build a simple pagination feature in a step-by-step approach for an easy understanding of the main logic.

At the bottom of this page is a jsFiddle live demo of this concept, feel free to skip all the explanations and move straight to the live demo if you can understand the code by yourself.

Read more »

SECURITY is at the heart of REST API design best practices because the vulnerability of an endpoint if not well secured can be exploited by an attacker to cause serious damage to the system or gain access to sensitive information using illegitimate credentials. In this article, we’ll look at how to design a Login REST API that is easy to understand for anyone and consume, well secured against various forms of attacks, and can be integrated into a new or existing system for proper user authentication.

Before we proceed to implementing the Login API, it is however very important to look at some of the common vulnerability of RESTful API’s, attacks and how to prevent them following REST API design common convetion.

DDoS attack

A distributed denial-of-service (DDoS) attack occurs when there’s a deliberate attempt to ruin the normal traffic of a server, network, or services by overwhelming the server with a flood of requests. This is arguably one of the most common forms of API attacks which are carried out with the sole purpose of preventing access to a targeted server or service.

How to prevent DDoS attack

The best way to prevent this kind of attack is to implement rate limiting on your server infrastructure. Rate limiting is a strategy for controlling the rate of requests sent or received by a network or server. It puts a cap on the number of requests someone can send to a targeted server within a certain timeframe.

Read more »