首页 > 解决方案 > Spring: Implement a share-via-link feature for web application

问题描述

I have a requirement where I need to implement a share-application-state-via-link feature.

My application is a video streaming single page application consisting of some dropdown options for user to filter out available videos and a video player to play the selected videos.

Now first on the basis of dropdown options , a user selects the available videos and add it to video player. At max 4 videos could be added. Now after that, I need to share this state of my application to some other user so I get a share link(just like Share answer in StackOverflow) and I send this to other user. This other user just need to hit this URL and it will load the exact state of application with videos added to player and dropdown populated with respective options.

My Approach:

I have a /getVideo rest service which fetches the video data and send it as json response back to angular based frontend. I have created a Share button which when clicked, creates a link by adding all the selected dropdown options something like: https://localhost:8080/MyApp/shared?genre=Action&type=web-series

I have created a method /shared which will take these params and call the /getVideo internally.

The problem here is, I need to load index.html when the above link is hit. I also have to send the getVideo data to be loaded with index.html and the application should function properly. Am not able to solve this problem and need help.

Is my approach correct? Is there any alternate way? Am using Spring-Boot for backend and angular2 for frontend.

Here is the /shared API:

@RequestMapping(value = "/shared", method = RequestMethod.GET)
public  String getSharedVideo(RedirectAttributes redirectAttributes, 
        @RequestParam(value="genre", required=false) String genre,
        @RequestParam(value="date", required=false) String date,
        @RequestParam(value="type", required=false) String type,
        @RequestParam(value="version", required=false) String version,
        @RequestParam(value="category", required=false) String category
        ){
    List<Lab> lab = null;
    try {
        lab = videoService.getVideo(genre, date, type, version, category);
        redirectAttributes.addAllAttributes(lab); // how to send this data to frontend
        return "index.html";

    } catch(Exception e) {
        LOGGER.error("EXCEPTION - " + e.getMessage());

    } 

Any help would be appreciated.

标签: javaspringangularrestspring-boot

解决方案


推荐阅读