locked
Page post view counter in Web API 2 RRS feed

  • Question

  • User-1399352090 posted

    Hello,

    I have page link Example : localhost/post/1244 

    • want to show page view counter by post id 
    • i want to save count of the post in database 
    • i want to show view count like YouTube counter example(200, 13K , 2M, 25.6 M)
    • i'm using web API 2 

     Please post any script or any suggestion best way to achieve with better performance

    Appropriate for best and quick response 

    Thursday, March 29, 2018 3:14 PM

All replies

  • User283571144 posted

    Hi smd_yasin,

    According to your description,I suggest you could create a web api controller.

    In this api controller, you could create two action.

    One is used to save the count of the post in database.

    Another one is used to read the count of the post in database according to the post ID.

    Like this:

        public class PostsController : ApiController
        { 
    
            [HttpGet]
            // GET api/<controller>/5
            public string Get(int id)
            {
    return "Counter"; } [HttpPost] // POST api/<controller> public string Post(int id) { // Add the counter number into database return "Save success"; } }

    Then you could access the api by using this url:

    GET api/Posts/{id}
    POST api/Posts/{id}

    Best Regards,

    Brando

    Monday, April 2, 2018 3:10 AM
  • User-1399352090 posted

    Hi smd_yasin,

    According to your description,I suggest you could create a web api controller.

    In this api controller, you could create two action.

    One is used to save the count of the post in database.

    Another one is used to read the count of the post in database according to the post ID.

    GET api/Posts/{id}
    POST api/Posts/{id}

    Hi Brando,

    Thank you for reply on this post.

    can you suggest or any script for view count like YouTube counter example(200, 13K , 2M, 25.6 M) 

    Monday, April 2, 2018 6:27 AM