Giter Club home page Giter Club logo

uni-api's Introduction

uni-api

This PHP script allow you to create a simple and universal REST API. Based on the original idea of Maurits van der Schee, Creating a simple REST API in PHP.

It use a MySQL Database.

uni-api support HTTP verbs GET, POST, PATCH, PUT and DELETE.

It have an authentication module.

Table Of Contents

Install

  • Save the file api.php and /core folder in your server document root

  • configure the config.php file with the requested parameters

  • Configure the database's models in models.json

    • the main use it will be automatically created with admin as username and password
  • launch install.php from the browser

  • Check if there is any errors while the installation

Configure the models

There is a models already written by me in the project folder.

Usage & API

The usage is realy simple:

user

Basic API

POST api.php/user
Logs user into the system

request:

{ 
    "username": "foo",
    "password": "foopass"
}

response:

{ 
    "username": "foo",
    "id": "foo_id",
    "token": "access_token"
}

PATCH api.php/user/:id
Update user

request: (you can send just username, password or both)

{ 
    "username": "new_foo_username",
    "password": "new_foo_pass"
}

response:

{ 
    "count": "# of the rows affected"
}

other tables

no relations

GET api.php/table
Get all the rows

response:

[
  { 
    //row_one
  },
  { 
    //row_two
  }
]

GET api.php/table/:id
Find row by ID

response:

{
    //all table's fields
}

PUT api.php/table/:id
Update a row in the database
Need to send the access_token in the Authorization header

request:

{ 
    //row's fields i want to update
}

response:

{ 
    "count": "# of the rows affected"
}

POST api.php/table
Create a new row
Need to send the access_token in the Authorization header

request:

{ 
    //table's field without id and update_date
}

response:

{ 
    "count": "# of the rows affected"
}

DELETE api.php/table/:id
Create a new row
Need to send the access_token in the Authorization header

response:

{ 
    "count": "# of the rows affected"
}

relations

hasOne

GET api.php/table/:id/relatedTable
Delete

  • Make a GET request to the table;
  • Get the relatedTable_id from the body;
  • Make a GET request to the relatedTeble with the obtained id.

PUT api.php/table/:id/relatedTable
Create a new relation
Need to send the access_token in the Authorization header

  • Just update the relatedTable_id field with the related element's id.

DELETE api.php/table/:id/relatedTable
Create a new row
Need to send the access_token in the Authorization header

  • Just set to NULL the relatedTable_id field

hasMany

GET api.php/table/:id/relatedTable
Get the realted elements of a determinate table
Need to send the access_token in the Authorization header

response:

{ 
    [
      { 
        //row_one
      },
      { 
        //row_two
      }
    ]
}

POST api.php/table/:id/relatedTable
Relate an existent element to the table
Need to send the access_token in the Authorization header

request:

{ 
    // an existent element to relate
}

response:

{ 
    "count": "# of the rows affected"
}

DELETE api.php/table/:id/relatedTable/:relatedId
Delete a relation between two elements
Need to send the access_token in the Authorization header

response:

{ 
    "count": "# of the rows affected"
}

WIP

  • User
    • User permission
    • Custom user
    • Better Multi User support
  • Files
    • Files support
  • Models
    • At State of Art you can't delete models or update it after. I want to make that possible.
    • Better configuration of the models. (I.E.: Required/Not Required fields)
  • Example
    • Write a complete example.

uni-api's People

Contributors

dariotecchia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.