Use HTTPie.
C:\>php -S 127.0.0.1:8080
[Thu Apr 1 12:12:12 2021] PHP 8.0.1 Development Server (http://127.0.0.1:8080) started
C:\>http post http://127.0.0.1:8080/[email protected]"&"last_name=Palpatine"&"first_name=Rey
HTTP/1.1 201 Created
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
{
"subscriber": {
"email_address": "[email protected]",
"first_name": "Rey",
"last_name": "Palpatine"
},
"success": "Record created."
}
C:\>http get http://127.0.0.1:8080/subscribers/4/
HTTP/1.1 200 OK
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
{
"activation_flag": 0,
"email_address": "[email protected]",
"first_name": "Rey",
"index": 4,
"last_name": "Palpatine"
}
C:\>http get http://127.0.0.1:8080/subscribers
HTTP/1.1 200 OK
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
[
{
"activation_flag": 0,
"email_address": "[email protected]",
"first_name": "Marc Anthony",
"index": 1,
"last_name": "Concepcion"
},
{
"activation_flag": 0,
"email_address": "[email protected]",
"first_name": null,
"index": 2,
"last_name": null
},
{
"activation_flag": 0,
"email_address": "[email protected]",
"first_name": null,
"index": 3,
"last_name": null
},
{
"activation_flag": 0,
"email_address": "[email protected]",
"first_name": "Rey",
"index": 4,
"last_name": "Palpatine"
}
]
If there are no records in the database, the API shall return an HTTP 204: No Content status code.
C:\>http get http://127.0.0.1:8080/subscribers
HTTP/1.1 204 No Content
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
C:\>http put http://127.0.0.1:8080/subscribers/3?last_name=Andrews"&"first_name=Kevin
HTTP/1.1 200 OK
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
{
"success": "Record of subscriber # 3 updated.",
"updates": {
"first_name": "Kevin",
"last_name": "Andrews"
}
}
C:\>http delete http://127.0.0.1:8080/subscribers/4
HTTP/1.1 200 OK
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
{
"success": "Record of subscriber # 4 deleted."
}
C:\>http get http://127.0.0.1:8080/subscribers/400
HTTP/1.1 404 Not Found
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
{
"error": "Subscriber does not exist"
}
C:\>http get http://127.0.0.1:8080
HTTP/1.1 400 Bad Request
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
{
"error": "Resource does not exist. Please provide a valid REST API resource."
}
C:\>http get http://127.0.0.1:8080/notsubscribers/1/
HTTP/1.1 400 Bad Request
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
{
"error": "Resource notsubscribers does not exist. Please provide a valid REST API resource."
}
C:\>http trace http://127.0.0.1:8080/subscribers
HTTP/1.1 405 Method Not Allowed
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
{
"error": "HTTP command TRACE without specified ID is not allowed. Please provide an acceptable HTTP command."
}
C:\>http post http://127.0.0.1:8080/subscribers/[email protected]"&"last_name=Palpatine"&"first_name=Rey
HTTP/1.1 409 Conflict Error
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
{
"error": "Posting/creating an already existing record. Please put/update an existing record or post/create a totally new record."
}
C:\>http post http://127.0.0.1:8080/subscribers/[email protected]"&"last_name=Palpatine"&"first_name=Rey
HTTP/1.1 405 Method Not Allowed
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
{
"error": "HTTP command POST with specified ID is not allowed. Please provide an acceptable HTTP command."
}
C:\>http post http://127.0.0.1:8080/subscribers/
HTTP/1.1 405 Method Not Allowed
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
{
"error": "HTTP command POST without providing parameters is not allowed. Please provide an acceptable HTTP command."
}
C:\>http put http://127.0.0.1:8080/subscribers/?last_name=Skywalker
HTTP/1.1 405 Method Not Allowed
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
{
"error": "HTTP command PUT without specified ID is not allowed. Please provide an acceptable HTTP command."
}
C:\>http put http://127.0.0.1:8080/subscribers/1
HTTP/1.1 405 Method Not Allowed
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
{
"error": "HTTP command PUT without providing parameters is not allowed. Please provide an acceptable HTTP command."
}
C:\>http delete http://127.0.0.1:8080/subscribers/
HTTP/1.1 405 Method Not Allowed
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Type: application/json; charset=UTF-8
Host: 127.0.0.1:8080
X-Powered-By: PHP/8.0.1
{
"error": "HTTP command DELETE without specified ID is not allowed. Please provide an acceptable HTTP command."
}
For more inquiries, please feel free to e-mail me at [email protected].
Thank you.
©️ 2021 Marc Concepcion