Simple search using restful api

I am a complete noob trying my hands on Ajax and jQuery. Following an online tutorial, I have successfully created a search engine using MySQL as the backend database;

<script> $(function() { $(".search_butn").click(function() { // getting the value that user typed var searchString = $("#input_box").val(); // forming the queryString var data = 'search='+ searchString; // if searchString is not empty if(searchString) { // ajax call $.ajax({ type: "POST", url: "search.php", //server-side script to db (mysql) data: data, beforeSend: function(html) { // this happens before actual call $("#results").html(''); $("#searchresults").show(); $(".word").html(searchString); }, success: function(html){ // this happens after we get results $("#results").show(); $("#results").append(html); } }); } return false; }); }); </script> <form method="post" action="search.php"> <div id="DIV"> <input type="text" name="search" id="input_box" class='input_box'/> <input type="submit" value="Search" class="search_butn" /> </div> </form><br/> <div> <div id="searchresults"> </div> <ul id="results" class="update"> </ul> </div> 

Now I want to take another step by doing a search using a RESTful api, like this one from Solr http://localhost:9090/solr/select?q=employee%3A%28james+blunt%29&wt=json&indent=true I need someone then to show me how I can do this.

+4
source share
1 answer

To create a RESTful API, you can write some PHP code to break the request URL. You should make Apache - your web server, I suppose - redirect all URLs with a specific prefix to this PHP script.

So let's say the user requests http://www.somename.com/my_api/some/shiny?suffix , you want Apache to redirect this URL to my_api.php script so that my_api.php can clip the entire URL address and do something based on this. To do this, Apache read apache mod_rewrite: http://httpd.apache.org/docs/current/mod/mod_rewrite.html

For a more detailed look at the RESTful API, I can suggest this tutorial: http://www.restapitutorial.com/

+1
source

Source: https://habr.com/ru/post/1480356/


All Articles