Skip to content

harshi03/network

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

REST Api with Slim PHP

This is a simple REST Web Service which allow:

  • Register a user
  • Login a user
  • List a user details
  • Delete a specific message by its id
  • Postman

๐Ÿšฅ Getting Started

This page will help you get started with this API.

Requirements

  • PHP 7.1
  • MySQL or MariaDB
  • Apache Server

Installation

Create a database

Run the following SQL script

-- --------------------------------------------------------
-- Database: `network`
-- --------------------------------------------------------
CREATE DATABASE IF NOT EXISTS `network` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `network`;

-- --------------------------------------------------------
-- Table structure for table `codes`
-- --------------------------------------------------------
CREATE TABLE `codes` (
  `id_code` int(10) UNSIGNED NOT NULL,
  `type` enum('VIP','VVIP') NOT NULL,
  `value` varchar(10) NOT NULL,
  `created_at` date NOT NULL,
  `updated_at` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------
-- Table structure for table `districts`
-- --------------------------------------------------------
CREATE TABLE `districts` (
  `id_district` int(10) UNSIGNED NOT NULL,
  `iso` varchar(2) NOT NULL,
  `district` varchar(80) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------
-- Table structure for table `users`
-- --------------------------------------------------------
CREATE TABLE `users` (
  `id_user` int(10) UNSIGNED NOT NULL,
  `guid` varchar(20) NOT NULL,
  `username` varchar(20) NOT NULL,
  `password` varchar(255) NOT NULL,
  `created_at` date NOT NULL,
  `id_district` int(10) UNSIGNED NOT NULL,
  `name` varchar(20) NOT NULL,
  `mobile` text NOT NULL,
  `email` varchar(20) NOT NULL,
  `age` int(10) NOT NULL,
  `gender` enum('Male','Female') NOT NULL DEFAULT 'Male',
  `pan_card` varchar(20) NOT NULL,
  `total_vehicle` int(10) NOT NULL,
  `total_male` int(10) NOT NULL,
  `total_female` int(10) NOT NULL,
  `type` varchar(10) NOT NULL,
  `updated_at` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------
-- Table structure for table `user_codes`
-- --------------------------------------------------------
CREATE TABLE `user_codes` (
  `id_user_code` int(10) UNSIGNED NOT NULL,
  `id_code` int(10) UNSIGNED NOT NULL,
  `id_user` int(10) UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------
-- Table structure for table `user_vehicles`
-- --------------------------------------------------------
CREATE TABLE `user_vehicles` (
  `id_user_vehicle` int(10) UNSIGNED NOT NULL,
  `id_vehicle` int(10) UNSIGNED NOT NULL,
  `id_user` int(10) UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------
-- Table structure for table `vehicles`
-- --------------------------------------------------------
CREATE TABLE `vehicles` (
  `id_vehicle` int(10) UNSIGNED NOT NULL,
  `name` varchar(80) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------
-- Indexes for table `codes`
-- --------------------------------------------------------
ALTER TABLE `codes`
  ADD PRIMARY KEY (`id_code`),
  ADD UNIQUE KEY `value` (`value`),
  ADD KEY `type` (`type`);

-- --------------------------------------------------------
-- Indexes for table `districts`
-- --------------------------------------------------------
ALTER TABLE `districts`
  ADD PRIMARY KEY (`id_district`);

-- --------------------------------------------------------
-- Indexes for table `users`
-- --------------------------------------------------------
ALTER TABLE `users`
  ADD PRIMARY KEY (`id_user`),
  ADD UNIQUE KEY `id_user_UNIQUE` (`id_user`),
  ADD UNIQUE KEY `user_UNIQUE` (`username`),
  ADD UNIQUE KEY `guid_UNIQUE` (`guid`),
  ADD UNIQUE KEY `email` (`email`),
  ADD KEY `fk_users_countries1_idx` (`id_district`);

-- --------------------------------------------------------
-- Indexes for table `user_codes`
-- --------------------------------------------------------
ALTER TABLE `user_codes`
  ADD PRIMARY KEY (`id_user_code`),
  ADD KEY `fk_users_codes1` (`id_code`) USING BTREE,
  ADD KEY `fk_users_users1` (`id_user`) USING BTREE;

-- --------------------------------------------------------
-- Indexes for table `user_vehicles`
-- --------------------------------------------------------
ALTER TABLE `user_vehicles`
  ADD PRIMARY KEY (`id_user_vehicle`),
  ADD KEY `id_vehicle` (`id_vehicle`),
  ADD KEY `id_user` (`id_user`);

-- --------------------------------------------------------
-- Indexes for table `vehicles`
-- --------------------------------------------------------
ALTER TABLE `vehicles`
  ADD PRIMARY KEY (`id_vehicle`);

-- --------------------------------------------------------
-- AUTO_INCREMENT for table `codes`
-- --------------------------------------------------------
ALTER TABLE `codes`
  MODIFY `id_code` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

-- --------------------------------------------------------
-- AUTO_INCREMENT for table `districts`
-- --------------------------------------------------------
ALTER TABLE `districts`
  MODIFY `id_district` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

-- --------------------------------------------------------
-- AUTO_INCREMENT for table `users`
-- --------------------------------------------------------
ALTER TABLE `users`
  MODIFY `id_user` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

-- --------------------------------------------------------
-- AUTO_INCREMENT for table `user_codes`
-- --------------------------------------------------------
ALTER TABLE `user_codes`
  MODIFY `id_user_code` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

-- --------------------------------------------------------
-- AUTO_INCREMENT for table `user_vehicles`
-- --------------------------------------------------------
ALTER TABLE `user_vehicles`
  MODIFY `id_user_vehicle` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

-- --------------------------------------------------------
-- AUTO_INCREMENT for table `vehicles`
-- --------------------------------------------------------
ALTER TABLE `vehicles`
  MODIFY `id_vehicle` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

-- --------------------------------------------------------
-- Constraints for table `users`
-- --------------------------------------------------------
ALTER TABLE `users`
  ADD CONSTRAINT `fk_users_countries1` FOREIGN KEY (`id_district`) REFERENCES `districts` (`id_district`) ON DELETE NO ACTION ON UPDATE NO ACTION;

-- --------------------------------------------------------
-- Constraints for table `user_codes`
-- --------------------------------------------------------
ALTER TABLE `user_codes`
  ADD CONSTRAINT `user_codes_ibfk_1` FOREIGN KEY (`id_user`) REFERENCES `users` (`id_user`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `user_codes_ibfk_2` FOREIGN KEY (`id_code`) REFERENCES `codes` (`id_code`) ON DELETE NO ACTION ON UPDATE NO ACTION;

-- --------------------------------------------------------
-- Constraints for table `user_vehicles`
-- --------------------------------------------------------
ALTER TABLE `user_vehicles`
  ADD CONSTRAINT `user_vehicles_ibfk_1` FOREIGN KEY (`id_user`) REFERENCES `users` (`id_user`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `user_vehicles_ibfk_2` FOREIGN KEY (`id_vehicle`) REFERENCES `vehicles` (`id_vehicle`) ON DELETE NO ACTION ON UPDATE NO ACTION;

Copy this project

  1. Clone or Download this repository
  2. Unzip the archive if needed
  3. Copy the folder in the htdocs dir
  4. Start a Text Editor (Atom, Sublime, Visual Studio Code, Vim, etc)
  5. Add the project folder to the editor

Install the project

  1. Go to htdocs dir
  • Windows
$ cd /d C:\xampp\htdocs
  • Linux
$ cd /opt/lampp/htdocs
  • MAC
$ cd applications/mamp/htdocs
  1. Go to the project folder
$ cd REST-Api-with-Slim-PHP
  1. Install with composer
$ composer install
Or
$ php composer.phar install  

๐Ÿ“ฆ Deployment

Database Schema

schema

๐Ÿ”ง Built With

๐Ÿ’ฏ Running the tests

Use RestEasy or Postman app for testing.

For authentication you can generate a new JSON Web Token with the url login.

Put the token on an HTTP header called Authorization. e.g.:

  • Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ
Header

Put the parameters on a Query Parameter.

Test

โ„น๏ธ Changelog

1.0.0.2 (03/29/2018)

  • Language: PHP
    Requirements:
    • PHP 7.1
    • MySQL or MariaDB
    • Apache Server

๐Ÿ“ License

This API is licensed under the MIT License - see the MIT License for details.

:response: Response Format

This API is strictly following https://github.com/adnan-kamili/rest-api-response-format/blob/master/README.md

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages