DEV Community

Otávio Cruz
Otávio Cruz

Posted on

API POSTfull

In my high school had programming classes, not so properly to learn something, them the programming teacher, only told the less than basic about REST API, to operate with databases. This way, i saw a new and simple way to solve the problem with REST, the way was use only post.
I saw problems, with get, pass params in the path, was very insecurity. And i wasn't to expose the php file so directly, and wasn't create multiple endpoint, then edits them.
A Example Below:

 $data = json_decode(file_get_contents("php://input"), true) ?? $_POST;
    if(isset($data['Operation'])){ 
        $WhoOperation = $data['Operation'];
        $content = $data['Content'];

        switch ($WhoOperation) {
            case 'select':
                SelectAllEmpresas($conn);
                break;
            case 'VerifyAccount':
                getUser($conn, $content);
                break;
            case 'selectUsers': 
                SelectUser($conn,$content);
                break;
            case 'addUser':
                addUser($conn,$content);
                break;
            case 'deleteUser':
                deleteUser($conn,$content);
                break;
            case 'alterUser':
                alterUser($conn,$content);
                break;  
            default:
                error404();
        }
    }else{
        error404();
    }
Enter fullscreen mode Exit fullscreen mode

Above, had all the operations of an CRUD, only with posts. Only when i learned more about API, and discussing with friends, i named it POSTfull. It's a predecessor of GraphQL, i think, actually. I was very funny this code today.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs