简体   繁体   中英

how to write a client side api in javascript

I've written the server side of an api, that serves html via json using REST via codeigniter. What I want to do next is write a client side api with javascript, to get the data from the server via the api, present it in the dom and bind events to it. Those events will then use the api to get new html, etc.

Now where do I begin? Can I use jquery in my api script and just do ajax calls to the api for every event triggered? Or are there better ways to do this? Are there any js libraries that help me do this? I've taken a look at backbone and require, bot I'm not sure if this is the correct purpose for those libraries.

Use fetch method to call web API from client side

 fetch('https://jsonplaceholder.typicode.com/todos').then(response => response.json()).then(json => console.log(json))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM