Page tree
Skip to end of metadata
Go to start of metadata


To get information about a post, url parameters  needs to be sent as follows to be identified as a item request. 

/post/https%3A%2F%2Fexample.blog%2Fpost%2F128319


In certain cases, it is not preferred to use item requests, in such cases we can fetch single record along with bulk records with the use of when condition.


 <Request method="GET" >
      <Sql id="posts" when="empty $url">
       select POST_ID, PAGE_URL,CREATION_DATE,
       from POST 
       where POST_URL is not null 
       order by CREATION_DATE desc
      </Sql> 
      <Sql id="post_info" >
        select * from 
        POST 
        where POST_URL = $url;
      </Sql>
</Request>

In the above example, when the `url` parameter is NOT passed, all the posts with non-null page url will be fetched. 

/posts?url=https://example.blog/post/128319


Avoid blank Post Info


{
  "post_info": [],
  "posts": [
    {
      "POST_ID": 8423,
      "PAGE_URL": "https://example.blog/post/128319",
      "CREATION_DATE": "2022-07-23 18:12:05.0",
    }
  ]
}


when  condition is applied post_info  to avoid empty display when $url is null.

<Sql id="post_info" when="not empty $url">
        select * from 
        METAMUG_POST 
        where METAMUG_POST_PAGE_URL = $url;
</Sql>


Related Example

Fetch data for null request parameter from table


  • No labels