Skip to content

huntertran/restapi-practices-impl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Design a pattern abiding RESTful API - A proof of concept

1. Abstract

REST APIs are nowadays the de-facto standard for Web applications. However, as more systems and services adapt REST architectural style, many problems arise regularly. To avoid these repetitive problems, developers could follow good practices and avoid bad practices. Thus, research on best and bad practices and how to design a simple but effective REST API is important. Yet, to the best of our knowledge, there are only a few concrete designs to recurring REST API practices, like "API Versioning". There are works on defining or detecting some practices, but not on designs to the practices. We present the most up-to-date list of REST API practices and propose designs, in the form of anti-patterns, to make a REST API compliant. We validate our anti-patterns with a survey and interviews of 55 developers.

This repository contains sample implementations of the patterns proposed in that research.

2. How to run

2.1. Prerequisition

  • MySQL running
  • Java 11
  • .NET Core 3

2.2. Setting up

2.2.1. Config database

Run the commands in file config\db.sql to create the sample database, user, and table.

-- from config\db.sql file
create database db_example;
create user 'springuser'@'%' identified by 'ThePassword';
grant all on db_example.* to 'springuser'@'%';

-- generate required table
CREATE TABLE `db_example`.`Students` (
  `Id` INT NOT NULL AUTO_INCREMENT,
  `Name` VARCHAR(45) NOT NULL,
  `Email` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE INDEX `Id_UNIQUE` (`Id` ASC));

It should show something like this (if you use command line to setup and run mysql):

mysql result

Change the location of the hosted MySQL database in these files:

  • dotnet/Utils/MyDbContext.cs
  • javaspring/src/main/resources/application.properties

20.151.2.26 is the IP address of the MySQL server. If you're hosting on the same machine, you can use localhost

2.2.2. Config Postman

You can just import the configs/testing.postman_collection.json file to your Postman to load all the test.