usmanlive presents a fake restful api for my students to practice api calls. Consult following Table for reference
| Route | Method | Input | Output | Comments | Test |
|---|---|---|---|---|---|
| http://usmanlive.com/wp-json/api/stories | GET | – | – | Returns an array of stories | Try It Yourself |
| http://usmanlive.com/wp-json/api/stories/:id | GET | – | – | Replace :id with the id of the story to fetch a single record | Try It Yourself |
| http://usmanlive.com/wp-json/api/stories/:id | DELETE | – | – | Replace :id with the id of the story to Delete | Try It Yourself |
| http://usmanlive.com/wp-json/api/stories | POST | {“title”:”–“,”content”:”–“} | Submit a new story to add | Try It Yourself | |
| http://usmanlive.com/wp-json/api/stories/:id | PUT | {“title”:”–“,”content”:”–“} | – | Replace :id with the id of the story to Edit | Try It Yourself |
Hit Refresh Stories to refresh data
Visit JQuery/Bootstrap based Single page frontend which accesses above restful api
Source Code for the above example can be found here
You can try https://reqbin.com/ to send api hits to test the above restful api
API Authentication
API Authentication can be done in numerous ways. One was is to use JSON Web Tokens. UsmanLive also present how a json web token based authentication can be implemented via following routes
| Route | Method | Input | Comments | try |
|---|---|---|---|---|
| http://usmanlive.com/wp-json/api/auth/register | POST |
{“name”:”-“,”email”:”-“,”password”:”-“}
|
Registers a User if not registered already else returns an error | Try It Yourself |
| http://usmanlive.com/wp-json/api/auth/login | POST |
{“email”:”-“,”password”:”usman”}
|
Returns a JSON Web Token | Try It Yourself |
| http://usmanlive.com/wp-json/api/auth/protected | POST | x-auth-token token set as header | Protected Route. Token is required |
Countries Auto Complete API
url: http://usmanlive.com/wp-json/api/countries
It accepts a querystring parameter named q and will return the array of coutries which matches the provided parameter e.g.
http://usmanlive.com/wp-json/api/countries?q=ak will return [“Kazakhstan”,”Pakistan”] use this api to practice autocomplete
Some Other Fake APIs