This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science courses and the like.

Overview

Simple PHP API v.1.0

This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science courses and the like. For this reason, it has only three EndPoints (resources) to use, and can be expanded according to the need.

As it is an instructional project, it is not recommended that it be applied in a production environment, as safety routines and tests have not been implemented. These resources must be researched and implemented, following the current rules, in addition to good practices. Built in PHP 7 (see below), it allows the beginner to understand the mechanisms of access to the resources of an API.

PHP 7.3.26 (cli) (built: Jan  5 2021 15:10:35) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.26, Copyright (c) 1998-2018 Zend Technologies

How to use this content?

This content has free license for use (CC BY-SA 4.0). If you want, collaborate in this repository any improvements that have been made.

Composer

Changes should be updated via composer dump-autoload -o on your local machine.

Documentation

Below are shown the resources available for using the API. After installation on the server, you can use the examples on how to use API data with: Node.js, PHP and Python, or try online.

Structure

+---api
|   \---new
|   \---search
|   \---update
+---src
|   \---Database
|   \---Helpers
|   \---User
\---vendor
    \---composer

Database

The development uses the MySQL 5 database, which can be changed at any time according to the need for use. The database should be configured in Database\Database.php

Scripts SQL

CREATE DATABASE <name>;
CREATE TABLE users (
    id          INT(3) 	    NOT NULL PRIMARY KEY AUTO_INCREMENT,
    name        VARCHAR(50) NOT NULL,
    email       VARCHAR(50) NOT NULL,
    username    VARCHAR(20) NOT NULL,
    password    VARCHAR(20) NOT NULL
)

Token

To use the API, include the access Token in src\User\UserModel.php method auth(). A suggestion for improvement this API is a Token distribution system.

Resources

POST: api/new/


url = 'http://URI/api/new/';

payload = {
    "name": "name", 
    "email": "email", 
    "username": "username", 
    "password": "password"
}

header = {
    "content-type": "application/json", 
    "Authorization": "YOUR_TOKEN"
}
Success
[
    {
        "status": "101",
        "info": "User Successfully Added"
    }
]
Warnings
[
    {
        "status": "102",
        "info": "Invalid Arguments Number (Expected Four)"
    }
]
[
    {
        "status": "103",
        "info": "Could Not Add User"
    }
]
[
    {
        "status": "104",
        "info": "User Already Exists"
    }
]

POST: api/search/

url = 'http://URI/api/search/';

payload = {
    "username": "username", 
    "password": "password"
}

header = {
    "content-type": "application/json", 
    "Authorization": "YOUR_TOKEN"
}
Success
[
    {
        "status": "201", 
        "id": 1,
        "name": "John Doe",
        "email": "[email protected]"
    }
]
Warnings
[
    {
        "status": "202", 
        "info": "Invalid Arguments Number (Expected Two)"
    }
]
[ 
    {
        "status": "203", 
        "info": "User Not Found or Incorrect username and/or password"
    }
]

PUT: api/update/

url = 'http://URI/api/update/';

payload = {
    "name": "name", 
    "email": "email", 
    "username": "username", 
    "password": "password"
}

header = {
    "content-type": "application/json", 
    "Authorization": "YOUR_TOKEN"
}
Success
[
    {
        "status": "301", 
        "info": "User Successfully Updated'
    }
]
Warnings
[
    {
        "status": "302", 
        "info": "Invalid Arguments Number (Expected Four)"
    }
]
[ 
    {
        "status":"303",
        "info": "User Not Found or Incorrect username and/or password"
    } 
]
[
    {
        "status": "304",
        "info": "Could Not Update User"
    }
]

Other Warnings
[
    {
        "status": "400", 
        "info": "Bad Request (Invalid Syntax)"
    }
]
[
    {
        "status": "401",
        "info": "Token Refused"
    }
]
[
    {
        "status": "402",
        "info": "Invalid or Missing Token"
    }
]
[
    {
        "status": "403",
        "info": "Payload Precondition Failed"
    }
]
[
    {"status": "404",
     "info": "Method Not Allowed"
    }
]
[
    {"status": "405",
     "info": "<SQL Code>"
    }
]
[
    {"status": "406",
     "info": "<Unknow>"
    }
]

Try Online

To test this API online, use:

How to cite this content

De Souza, Edson Melo (2021, March 13). Simple PHP API v.1.0.
Available in: https://github.com/EdsonMSouza/simple-php-api

Or BibTeX for LaTeX:

@misc{desouza2020phpapi,
  author = {De Souza, Edson Melo},
  title = {Simple PHP API v.1.0},
  url = {https://github.com/EdsonMSouza/simple-php-api},
  year = {2020},
  month = {March}
}

License

CC BY-SA 4.0

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

CC BY-SA 4.0

You might also like...
微信支付 API v3 的 PHP Library,同时也支持 API v2

微信支付 WeChatPay OpenAPI SDK [A]Sync Chainable WeChatPay v2&v3's OpenAPI SDK for PHP 概览 微信支付 APIv2&APIv3 的Guzzle HttpClient封装组合, APIv2已内置请求数据签名及XML转换器,应

API documentation API SCB EASY APP

SCB-API-EASY V3.0 API documentation SIAM COMMERCIAL BANK PUBLIC COMPANY LTD. API SCB Easy V3 endpoint = https://fasteasy.scbeasy.link 1.0. Get balance

Courier API adalah project API untuk mengetahui ongkos kirim Logistik-logistik pengiriman barang antar kota & International
Courier API adalah project API untuk mengetahui ongkos kirim Logistik-logistik pengiriman barang antar kota & International

Courier API Courier API adalah project API untuk mengetahui ongkos kirim Logistik-logistik pengiriman barang antar kota (dalam negeri) & International

LaraBooks API - Simple API for iOS SwiftUI app tests.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Simple PHP API client for tube-hosting.com rest API

Tube-Hosting API PHP client Explanation This PHP library is a simple api wrapper/client for the tube-hosting.com api. It is based on the provided docu

GraphQL API to Studio Ghibli REST API

GhibliQL GhibliQL is a GraphQL wrapper to the Studio Ghibli REST API Usage First, you'll need a GraphQL client to query GhibliQL, like GraphQL IDE Con

A RESTful API package for the Laravel and Lumen frameworks.
A RESTful API package for the Laravel and Lumen frameworks.

The Dingo API package is meant to provide you, the developer, with a set of tools to help you easily and quickly build your own API. While the goal of

The efficient and elegant JSON:API 1.1 server library for PHP

Woohoo Labs. Yin Woohoo Labs. Yin is a PHP framework which helps you to build beautifully crafted JSON:APIs. Table of Contents Introduction Features W

The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructure and leverage the power of 1Password Secrets Automation

1Password Connect PHP SDK The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructu

Owner
Edson M. de Souza
Professor & Researcher at Information Technology
Edson M. de Souza
Best resources restful api for developers (with JSON:API standar specification design)

List API Best resources restful api for developers (with JSON:API standar specification design). API Resource Endpoint Name Resource Description Al Qu

Noval 2 Jan 18, 2022
This small POC aims to show how Symfony is able, natively without modifications, to use subdirectories for Entities, Repositories, controllers, views…

POC - Using Sub Directories in a Symfony Project This small POC aims to show how Symfony is able, natively without modifications, to use subdirectorie

Yoan Bernabeu 2 May 12, 2022
JSON:API serializer for PHP resources

kwai-jsonapi A JSON:API serializer for PHP classes using PHP attributes. Currently, this library has no support for links. Installation composer requi

Franky Braem 1 Jan 19, 2022
Best resources restful api for developers

Best resources restful api for developers (with JSON:API standar specification design).

Noval 2 Jan 18, 2022
Doctrine-like fixtures integration for Shopware 6.

Shopware 6 Fixtures Did you ever want to create and load Doctrine-like fixtures in your Shopware 6 plugin? Look no further! This plugin provides an ul

Familiy Office 0 Oct 29, 2021
PHP 8.1 like legacy enum (Experimental Alpha Version)

flux-legacy-enum PHP 8.1 like legacy enum Experimental Alpha Version Installation COPY --from=docker-registry.fluxpublisher.ch/flux-enum/legacy:latest

fluxlabs 1 Dec 12, 2022
Like FormRequests, but for validating against a json-schema

JSON Schema Request Laravels Form Request Validation for JSON Schema documents Installation composer require wt-health/laravel-json-schema-request Us

Webtools Health 1 Feb 3, 2022
Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and / or RESTful API

Luracast Restler ![Gitter](https://badges.gitter.im/Join Chat.svg) Version 3.0 Release Candidate 5 Restler is a simple and effective multi-format Web

Luracast 1.4k Dec 14, 2022
Laravel api tool kit is a set of tools that will help you to build a fast and well-organized API using laravel best practices.

Laravel API tool kit and best API practices Laravel api tool kit is a set of tools that will help you to build a fast and well-organized API using lar

Ahmed Esa 106 Nov 22, 2022
Chargebee API PHP Client (for API version 2 and Product Catalog version 2.0)

chargebee-php-sdk Overview This package provides an API client for Chargebee subscription management services. It connects to Chargebee REST APIs for

GLOBALIS media systems 8 Mar 8, 2022