User search in RESTful spring API - spring

So basically, I have a spring API with MySQL database and I need to be able to perform search of a user by his name in front-end web app which is using my API. The trick is that I need a kind of google search so by typing, lets say, 3 letters, list of all users who's name starts from these 3 letters would be returned from the API to the web app. By typing or deleting any letter, list should change dynamically.
My question is how can implement this kind of "dynamic" search in my API. What should requests look like? What should the whole architecture of the process in the API look like?

There are a number of ways to pull this off. Coding this in your API is probably going to be the least efficient. I would recommend using SOLR or Lucene to index the data you want to search on. Your front-end will have some JS that will update your list when characters are entered or deleted in the text field.
JQuery provides a plugin that might be just what you're looking for from the UI.
https://jqueryui.com/autocomplete/

Related

How to search for web and images results from Google Custom Search JSON API?

I'm implementing Google's Custom Search JSON API into my application which shall search for both web and images. I am able to query for web and images independently.
For web: https://www.googleapis.com/customsearch/v1?key=${key}&start=${start}&cx=${cx}&q=${searchVal}
For images: https://www.googleapis.com/customsearch/v1?key=${key}&searchType=image&start=${start}&cx=${cx}&q=${searchVal}
This works perfectly. However, as you can see, I have to make 2 separate requests to get the web results and the images for a single query value. This is an issue since it makes room for Google's search query quota to be exceeded. So, I need to find a way to make a single request which returns me both the web and image results for a particular search value. Any help or recommendation would be appreciated.

REST API design for keyword based query

I am trying to architect a REST API design to give the best results to users based on keywords. User will have the option to select keywords (Like 'new', 'top rated', 'open now') and the REST API shall return the best result sets based on the selected keyword.
This is somewhat similar to how Google Maps is implemented. (See the image in the link below for reference) - User can select 'Open now' and 'Top rated', and Google shows the top rated stores that are open.
https://www.reddit.com/r/GoogleMaps/comments/j07cf1/does_anyone_else_find_the_google_maps_search/
I am using Spring as our backend framework and I am lost and not sure where to start. I believe the SQL query should be constructed based on selected user keywords but not sure if this is the right way to do it.
Can anyone familiar with this subject share some ideas on this?
you could use spring boot backed micro services to perform this. you may want to have an api business services (REST endpoint) that interacts with your client and then a core service (REST endpoint) to interact with your DB
You can take the benefit of framework like graphql etc.

Mix Panel API web segmentation and personalisation

Hi I am interested in using Mix Panel on a web site to track customers events. I would like to know if there is any way to use the api to personalise the web site per customer, similar to segmentation for emails.
I would like to query the api for a singular customer asking whether they have achieved several events.
For example something like
If customer has clicked out and last visit greater than a month ago display a banner advert.
Mixpanel does not seem like a correct tool for the job you describe here.
While theoretically this might be possible (via Mixpanel's HTTP API), this will create unnecessary architectural complexity and add extra latency. If you need to customize your web site per user, store any user state in a database like MySQL or PostgreSQL. This will be both faster and easier.

how to implement Complex Web API queries in ASP Core

I'm new to web API design, so I've tried to learn best practices of web API design using these articles:
1.Microsoft REST API Guidelines
2.Web API Design-Crafting Interfaces that Developers Love from "Apigee"
Apigee is recommending web API developers to use these recommendations to have better APIs.
I quote here two of the recommendations:
I need C# code for implementing these recommendations in my Web APIs (in ASP Core) which is a back-end for native mobile apps and AngularJs web site.
Sweep complexity behind the ‘?’
Most APIs have intricacies beyond the base level of a resource. Complexities can include many states that can be updated, changed, queried, as well as the attributes associated with
a resource.
Make it simple for developers to use the base URL by putting optional states and attributes behind the HTTP question mark. To get all red dogs running in the park:
GET /dogs?color=red&state=running&location=park
Partial response allows you to give developers just the information they need.
Take for example a request for a tweet on the Twitter API. You'll get much more than a typical twitter app often needs - including the name of person, the text of the tweet, a timestamp, how often the message was re-tweeted, and a lot of metadata.
Let's look at how several leading APIs handle giving developers just what they need in
responses, including Google who pioneered the idea of partial response.
LinkedIn
/people:(id,first-name,last-name,industry)
This request on a person returns the ID, first name, last name, and the industry.
LinkedIn does partial selection using this terse :(...) syntax which isn't self-evident.
Plus it's difficult for a developer to reverse engineer the meaning using a search engine.
Facebook
/joe.smith/friends?fields=id,name,picture
Google
?fields=title,media:group(media:thumbnail)
Google and Facebook have a similar approach, which works well.
They each have an optional parameter called fields after which you put the names of fieldsyou want to be returned.
As you see in this example, you can also put sub-objects in responses to pull in other information from additional resources.
Add optional fields in a comma-delimited list
The Google approach works extremely well.
Here's how to get just the information we need from our dogs API using this approach:
/dogs?fields=name,color,location
Now I need C# code that handles these kind of queries or even more complex like this:
api/books/?publisher=Jat&Writer=tom&location=LA?fields=title,ISBN?$orderBy=location desc,writerlimit=25&offset=50
So web API users will be able to send any kind of requests they want with different complexities, fields, ordering,... based on their needs.

Google Web search API (not custom search)

So google pulled the SOAP API back in 2006, and depreciated the REST API last year. Even though the REST api still works fine, I was wondering if anyone here knows an alternative for the web search. I am not talking about Custom search API (that thing is horrible with a 100 queries/day limit).
Also, I am currently using the REST api for a custom application. I have noticed mixed (and very unreliable) results if I pass search operators such as inurl: or site: with my queries. Does anyone know if these even work with the REST Api?
The search parameters do work for Googles deprecated REST API. But search results often do not equal the ones from a regular Google search. Most likely because the two do not (and never will) use the same data index.
YAHOOs BOSS could be a (non-free) alternative
Microsoft does offer a simple and free restful API for BING

Resources