How to convert CSV to JSON in PHP

In this example I am going to show you how to convert CSV to JSON using PHP programming language. CSV stands for comma separated values and JSON stands for JavaScript Object Notation. These are actually data formats used for representations. Having data formats in CSV and JSON are advantageous because of their light-weight, easy to representation and easy to parse. JSON format is currently widely used in REST response.

Continue

Django 3, MySQL REST API Angular 10 CRUD Example

Here in this tutorial I am going to explain how to integrate Django REST API with Angular framework. CRUD stands for Create, Read, Update and Delete operations which will be performed from UI (User Interface) using Angular framework and on server side Django framework and MySQL server are used. The Angular framework will be used in this example for representing the UI (User Interface) where end users will perform CRUD operations.

Continue

How to mask a Field or an Attribute in Java

Here I am going to show you how to mask a field or an attribute in Java programming language. This kind of situation occurs when you are dealing with mainly debit or credit cards. So you have a POJO or model class for your card (debit or credit) but for security reason you do not want to display the card number, then you need to mask the card number. Masking something means you want to replace the actual value with some other value, for example, your card number is 3456…

Continue

CodeIgniter 4 REST API, MySQL and Angular 10 CRUD Example

I am going to show you an example on Angular CodeIgniter 4 REST API MySQL CRUD. CRUD is an acronym and stands for Create, Read, Update and Delete operations. REST or RESTful is a Representational State Transfer which defines an architectural style in software engineering. The REST API works on HTTP or HTTPS protocol. The Angular framework will be used in this example for representing the UI (User Interface) where end users will perform CRUD operations.

Continue

Junit 5 Mockito Verify Example

In this example I am going to show you how to verify a method has been executed at least. Why do you need to verify method execution? Consider the void method, in your Java class, which you want to perform Junit test case on it and you don’t have any way to tell whether your method successfully tested or not. So here you are left with only one option, i.e., to check whether your method was executed or not. If your method was executed then you know that your code…

Continue

Junit 5 Expected Exception using Assertions.assertThrows()

This example will show you how to work with expected exception using Junit 5 Assertions.assetThrows(). Junit 4 (at least 4.7 version) provides expected attribute with @Test annotation, where you can mention what exception you are expecting from your test method but Junit 5 does not provide such thing. Junit 5 provides assertThrows() that can be used to check the expected exception. A Java unit test should verify correct exception thrown in exceptional case and no exception should be thrown in normal case. assertThrows() asserts that execution of the supplied executable…

Continue

How to return Different Data Formats (JSON, XML) from Spring REST API

Here I am going to show you an example on how to return different data formats from REST API using Spring Boot framework. You may have a requirement that you need to return multiple formats, such as XML, JSON, etc., from the REST response, then this example may help you. This example will return XML and JSON format depending on your HTTP settings. By default the REST will send you the JSON response. You need to set key Accept‘s value in HTTP Headers to text/xml or application/xml to get the…

Continue

Mock an Autowired Value Field in Spring with Junit 5

In this example I am going to show you how to mock an autowired field in Spring boot framework with Junit 5. When you use @Value annotation in Spring beans to read the value from properties file and later when you want to perform Junit test then you also need to pass value for this autowired field value otherwise you won’t be able to cover your testing. Read if you need Junit 4 version of testing for Spring’s autowired field value. Now it is really cumbersome to place a properties…

Continue

REST API CRUD Example in CodeIgniter 4 Framework

Here I am going to show you how to build REST web services in PHP based Codeigniter 4 framework. CodeIgniter 4 is the upcoming version of the framework and it is still under development, intended for use with PHP 7.2 or higher version. REST is an acronym that stands for Representational State Transfer (RESTful), which is an architectural style for distributed applications. PHP based CodeIgniter framework enables developers to develop the projects much faster, it provides the core part that can easily be extended or replaced completely to make the…

Continue

How to merge multiple CSV files into one using Python

In this tutorial I am going to show you how to merge multiple CSV files into one in Python. I am using two CSV files for this example. You may need to merge multiple CSV files into one in some situations for your business requirements. Your different CSV files might have some common headers amongst them and when you merge those CSV files you want to put unique headers for the final CSV file. Under each header you will write values from different CSV files. If there is no value…

Continue