{"id":16986440,"url":"https://github.com/andresharpe/quick-api","last_synced_at":"2026-04-11T15:31:36.854Z","repository":{"id":183108654,"uuid":"98977321","full_name":"andresharpe/quick-api","owner":"andresharpe","description":"A how-to guide for spinning up a fully functional and documented REST API in 30 minutes (with good connectivity) and with absolutely no coding.","archived":false,"fork":false,"pushed_at":"2017-08-01T21:12:49.000Z","size":27,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T02:09:34.760Z","etag":null,"topics":["apache","api","bootstrap","crud","docker","mysql","php","swagger-ui"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andresharpe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-08-01T08:19:12.000Z","updated_at":"2017-08-01T20:46:29.000Z","dependencies_parsed_at":"2024-02-18T20:45:23.650Z","dependency_job_id":null,"html_url":"https://github.com/andresharpe/quick-api","commit_stats":null,"previous_names":["andresharpe/quick-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andresharpe/quick-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresharpe%2Fquick-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresharpe%2Fquick-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresharpe%2Fquick-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresharpe%2Fquick-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andresharpe","download_url":"https://codeload.github.com/andresharpe/quick-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresharpe%2Fquick-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31686131,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-11T13:07:20.380Z","status":"ssl_error","status_checked_at":"2026-04-11T13:06:47.903Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apache","api","bootstrap","crud","docker","mysql","php","swagger-ui"],"created_at":"2024-10-14T02:45:46.302Z","updated_at":"2026-04-11T15:31:36.813Z","avatar_url":"https://github.com/andresharpe.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# quick-api\nA how-to guide for spinning up a fully functional REST API in 30 minutes (assuming fast connectivity) and with no coding!\n\nBuild a REST API supporting GET/POST/DELETE/PUT and basic Swagger documentation using free tools (docker, apache, php, mysql and the very cool mevdschee/php-crud-api script developed by Maurits van der Schee).\n\n## Introduction\nSo you have a small team. You have a tight deadline to develop a Minimum Viable Product (MVP) or demo - complete with REST API, database server, possibly a responsive web portal and/or a mobile application.\n\nYou want to get everyone on the team going as quickly as possible and have a good idea what the models will look like in your freshly minted Model-View-Controller (MVC) design.\n\nGetting the test REST API out there ASAP will get everybody going in parallel and help refine requirements.\n\n## Solution Overview\nThe solution comprises of\n- [Docker](https://docker.com) to help you run a isolated instances/environments of the four main solution components (web server, database and scripting language, documentation server)\n- [php-crud-api](https://github.com/mevdschee/php-crud-api) developed by Maurits van der Schee, a really clever, lean and very feature rich single file PHP script that exposes a database as an API\n- [PHP/Apache](https://hub.docker.com/_/php/) docker container to host and execute the script\n- A [MySQL](https://hub.docker.com/_/mysql/) docker container to define our entities and store them in\n- The single file [Adminer](https://hub.docker.com/_/adminer/) script that will allow us to view/modify our MySQL data, running in a Docker container\n- A [Swagger](https://hub.docker.com/r/swaggerapi/swagger-ui/) docker container to display the API documentation and test the API that is emitted automatically by the *php-crud-api* script\n\n\n## The Step-by-step Guide\n\nFor this project I am using an Ubuntu Server (16.04.2 LTS with Xubuntu Desktop), but other than the [initial installation of Docker](https://docs.docker.com/engine/installation/), this tutorial should work for you.\n\n#### Step 1: Get Docker\nFor Debian and Ubuntu based systems you can simply install directly from the Docker website.\n\n```bash\ncurl -sSL https://get.docker.com/ | sh\nsudo usermod -aG docker andre\n```\n#### Step 2: Get Docker Compose\nI initially tried getting the docker environment setup using only the Docker command line and Dockerfiles, but it is far easier with the composer, so on Ubuntu just type..\n\n```bash\nsudo apt-get install docker-compose -y\n```\nand you're done.\n#### Step 3: Create a folder for your project\n```\ncd ~/projects\n```\n```\nmkdir quick-api\ncd quick-api\n```\nCreate a folder to host our website source code (our php/apache docker will point here)\n```\nmkdir src\n```\nWe will also need to customise the default docker image for php/apache (essentially create a new image deriving from it) and will do so in this folder..\n```\nmkdir php-mysqli\n```\n#### Step 4: Create Docker Composer definition\nCreate a file called *docker-compose.yml* in this folder. It will contain the intructions for Docker Compose to create the three images (mysql, adminer to manage the database and php/apache for hosting the php-crud-api script)\n```yaml\n# docker-compose.yml\n\nversion: '2'\n\nservices:\n\n  mysql:\n    image: mysql:8.0.2\n    environment:\n      MYSQL_ROOT_PASSWORD: \"wookie\"\n      MYSQL_DATABASE: \"api\"\n    volumes:\n      - mysql_data:/var/lib/mysql\n\n  adminer:\n    image: adminer\n    ports:\n      - 8080:8080\n    depends_on:\n      - mysql\n\n  php:\n    build: ./php-mysqli\n    ports:\n      - 80:80\n    volumes:\n      - ./src:/var/www/html\n    depends_on:\n      - mysql\n\nvolumes:\n  mysql_data:\n```\nThe *volumes* directive in the mysql section makes sure that your database changes survives an image (or PC) reboot (as Docker containers are [ephemeral](http://www.dictionary.com/browse/ephemeral) and you'll lose all file system  changes inside a Docker container when it is shut down).\n\nIn the *php* section the *volumes* directive also creates a map to a subfolder outside the php Docker image (*./src* in our project folder).\n\n#### Step 5: Add mysqli to php-apache\nThere are quite a few official [php images for Docker](https://hub.docker.com/_/php/), but none of them seem to contain the [*mysqli*](https://en.wikipedia.org/wiki/MySQLi) extension enabled, which the *php-crud-api* script depends on.\n\nCreate a file called *Dockerfile* in the *phpmysql* subfolder. Let's add both the inclusion of *mysqli* with PHP and activate the *rewrite* module of Apache whilst we at it (we will need this too).\n\n```\n#php-mysqli/Dockerfile\n\nFROM php:7.1.7-apache\n\nRUN apt-get update \\\n      \u0026\u0026 apt-get install -y mysql-client libmysqlclient-dev \\\n      \u0026\u0026 docker-php-ext-install mysqli \\\n      \u0026\u0026 a2enmod rewrite\n```\n\n#### Step 6: Build the containers\nJust before we get the api script installed, let's test that our containers all work.\n\n(Make sure you are on a fast connection and feel like having a coffee. If not you can offer to make one for your spouse or parents.)\n\n```\ndocker-compose up -d\n```\nDocker will launch into an epic and magical excursion to pull the referenced images, cache them, build the php image from our Dockerfile and start up three containers in the background (*-d*).\n```\n...\nCreating quickapi_mysql_1\nCreating quickapi_php_1\nCreating quickapi_adminer_1\n\nandre@devbox:~/projects/quick-api$\n```\nTo check if your containers are running succesfully type *docker ps*..\n```\nandre@devbox:~/projects/quick-api$ docker ps\nCONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES\nd864a9aa2542        adminer             \"entrypoint.sh doc...\"   6 minutes ago       Up 6 minutes        0.0.0.0:8080-\u003e8080/tcp   quickapi_adminer_1\nd7b5b6d1dda9        quickapi_php        \"docker-php-entryp...\"   6 minutes ago       Up 6 minutes        0.0.0.0:80-\u003e80/tcp       quickapi_php_1\n46f413739138        mysql:8.0.2         \"docker-entrypoint...\"   6 minutes ago       Up 6 minutes        3306/tcp                 quickapi_mysql_1\nandre@devbox:~/projects/quick-api$\n```\n\n#### Step 7: Test the stack\nA simple way to make sure that most of the new stack is working, is to create a new file in the *src* folder called *index.php* with the following content:\n```php\n\u003c?php\n  // src/index.php\n  phpinfo();\n?\u003e\n```\nThen simply open the browser on your development server and browse to http://localhost\n\nYou should see - and I quote directly from the [PHP manual](http://php.net/manual/en/function.phpinfo.php) - \"a large amount of information about the current state of PHP. This includes information about PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License.\"\n\n![phpinfo result](https://user-images.githubusercontent.com/7415999/28838867-fd2dc734-76f1-11e7-9992-77ae491a8e1f.png \"phpinfo Results\")\n\n#### Step 8: Create a table in MySQL\nNext, point your browser to *http://localhost/8080*. You should see the following page.\n\n![screenshot_2017-08-01_19-49-31](https://user-images.githubusercontent.com/7415999/28839088-c8ee461e-76f2-11e7-910c-211870d7565f.png)\n\nAs per the screenshot above, set the **System** to *MySQL*, **Server** field to *mysql*, **Username** to *root*, **Password** to *wookie* and **Database** to *api*. Click on *Create table* and create a table called **movies** with the following four fields:\n\n- id, unsigned integer, Autonumber\n- name, varchar(128)\n- year, unsigned smallint\n- director, varchar(64)\n\nThe screen should look similar to this:\n\n![screenshot_2017-08-01_19-57-45](https://user-images.githubusercontent.com/7415999/28839509-2e7b0e26-76f4-11e7-8c04-530a8ea0f080.png)\n\nClick on the *Save* button and then on *New item* to create the first record. Leave *id* blank, and enter a movie name, year and director like so:\n\n![screenshot_2017-08-01_20-08-06](https://user-images.githubusercontent.com/7415999/28839863-4829ea30-76f5-11e7-8d28-9ed110a31ec8.png)\n\n#### Step 9: Create the API\n\nThe final step is to install the single file php-api-api script and to configure it.\n\nCreate an *api* sub folder in *./src*\n```\nmkdir src/api\ncd src/api\n```\nThen download the *api.php*  [script](https://raw.githubusercontent.com/mevdschee/php-crud-api/master/api.php)\n```\nwget https://raw.githubusercontent.com/mevdschee/php-crud-api/master/api.php\n```\n...edit the file and uncomment and change the following few lines (circa line 2711) to point the script to the correct database.\n\n```php\n\u003c?php\n...\n// uncomment the lines below when running in stand-alone mode:\n\n//$api = new PHP_CRUD_API(array(\n// \t'dbengine'=\u003e'MySQL',\n// \t'hostname'=\u003e'localhost',\n// \t'username'=\u003e'ist-test',\n//\t'password'=\u003e'HowF72yIv0UxPZyS',\n// \t'database'=\u003e'ist-data-test02',\n// \t'charset'=\u003e'utf8'\n//));\n//$api-\u003eexecuteCommand();\n\n\n$api = new PHP_CRUD_API(array(\n\t'dbengine'=\u003e'MySQL',\n\t'hostname'=\u003e'mysql',\n\t'username'=\u003e'root',\n\t'password'=\u003e'wookie',\n\t'database'=\u003e'api',\n \t'charset'=\u003e'utf8'\n));\n$api-\u003eexecuteCommand();\n```\nSave the file and then create a file called *.htaccess* in the same folder (this will allow the apache server inside the php container to 'rewrite' the url in the browser to make **http://localhost/api/api.php/movies** equivalent to **http://localhost/api/movies** which is far cooler)\n\nHave it contain:\n```\n#src/api/.htaccess\n\nRewriteEngine On\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteRule ^(.*)$ api.php/$1 [L,QSA]\n```\n\n#### Step 10: Done! Test your API\n\nOpen a browser and try **http://localhost/api/movies/1**. You should see :\n```json\n{\"id\":1,\"name\":\"Star Wars: Episode IV - A New Hope\",\"year\":1977,\"director\":\"George Lucas\"}\n```\n\n#### Step 11: Add Swagger documentation and test your API\n\nThe php-crud-api script automatically generates [Swagger](https://swagger.io/) documentation, and Swagger-UI can easily be added to the Docker Compose script. Add the *swagger* service just below the *php* service as follows.\n\n```yaml\n# docker-compose.yml\n\nversion: '2'\n\nservices:\n\n...\n\n  swagger:\n    image: swaggerapi/swagger-ui\n    environment:\n      API_URL: \"http://localhost/api/api.php\"\n    ports:\n      - 8081:8080\n    depends_on:\n      - mysql\n\nvolumes:\n  ...\n```\nRun the following command to shut down and restart the docker containers.\n\n```\ndocker-compose down\n```\n```\ndocker-compose up -d\n```\nFinally browse to *localhost:8081* to view full Swagger documentation for your new API.\n\n![screenshot_2017-08-01_22-36-32](https://user-images.githubusercontent.com/7415999/28845969-06986bea-770a-11e7-850c-7bd058e95d7e.png)\n\nYou can use Swagger to test creating, deleting, updating and listing entities via you newly minted REST API. You can also add as many tables via *adminer* as you like and the API will automatically be extended with new entities.\n\nEnjoy!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandresharpe%2Fquick-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandresharpe%2Fquick-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandresharpe%2Fquick-api/lists"}