30 min
Saito
  1. 1. Information
    1. 1.1. Ingredients
    2. 1.2. Functions
  2. 2. Create the application
    1. 2.1. Frontend
    2. 2.2. Backend
  3. 3. Customize the application
    1. 3.1. Frontend
    2. 3.2. Backend
  4. 4. Deploy the application
    1. 4.1. Backend
    2. 4.2. Frontend
  5. 5. Download
  6. 6. Version

Even if an application simply shows results of search on Wikipedia, it seems like a lot of work to build one. But it’s easy if you use K5 Playground. See this tutorial and you’ll get it done in 30 minutes.

Information

Ingredients

  • Template: Simple Search
  • API Loigcs: Wikipedia Search Page

Functions

  • Searching on Wikipedia.
  • Displaying results of the search.

Create the application

Frontend

  1. Choose the Simple Search Template.

  2. Customize the UI in K5 Playground.

Backend

  1. Change the WebAPI name.

    • Rename sample_products to articles.
  2. Edit the API Logic of GET /articles.

    1. Click GET /articles endpoint.

    2. Remove Fetch Document API Logic.

    3. Add the Search Wiki Page API Logic from Search menu at the right pane.

    4. Modify the code as follows.

      1. Set search keyword

        1
        var srsearch = req.swagger.params.keyword.value;
      2. Set total pages

        1
        var srlimit =  req.swagger.params.limit.value;
      3. Set offset for pages

        1
        var sroffset =  req.swagger.params.offset.value;
  3. Download the application.

Customize the application

Frontend

  1. Edit the actions/ProductActionCreators.js.

    Change the parameter of dispatch called in getProducts method.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    AppDispatcher.dispatch({
    type: ActionTypes.GET_PRODUCTS,
    data: {
    products: productList.data.query.search.map(
    // NOTE: Since we need _id to show detail page, use the title of page.
    product => Object.assign({}, product, { _id: product.title }),
    ),
    count: productList.data.query.searchinfo.totalhits,
    },
    });
  2. Edit the components/pages/ProductListPage.js.

    Change card function to show a result of wiki search.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    const card = value => (
    <VerticalCard002
    key={value.title}
    title={
    <a
    href={`https://en.wikipedia.org/wiki/${value._id}`}
    target="_blank"
    rel="noopener noreferrer"
    >
    {value.title}
    </a>
    }
    contentStyle={styles.cardContent}
    highlighted={value.snippet.replace(/<[^>]*>/gm, '')}
    highlightedStyle={styles.cardHighlighted}
    />
    );

Backend

Nothing to be edited.

Deploy the application

Finally, all you need to do is deploying backend and frontend.

Backend

1
2
cd backend
cf push [APP_NAME]

Frontend

1
2
3
4
5
6
cd frontend
npm install
set API_URL=[Backend URL] # for Windows
export API_URL=[Backend URL] # for Mac/Linux
npm run build
cf push [APP_NAME] -p public

Download

NOTE: Removed all actions and components not in use.

Version

  • Simple Search Template: v1.0.0