Β· 3 min read

How to Use Python to Build a Basic Microservice (with a Real Jisho API Example)

Are you curious about what a microservice looks like in Python? In this article, I’ll walk you through creating a simple but complete microservice using Python and Flask that calls a real external API: the Jisho.org API.

The goal is to keep it minimal, readable, and useful β€” perfect for beginners or those wanting a practical example.


🧠 What This Microservice Does

This microservice exposes a simple webpage where users can:

  1. Input a Japanese word (like 猫, 勉強, or θ΅°γ‚‹)
  2. Submit the form
  3. Get instant results from the Jisho.org API

The app has two main pages:

  • / – The index page with a search form
  • /search – The result page that fetches and displays definitions

This simulates a classic frontend-backend interaction flow, with the backend serving both HTML and dynamic content from a third-party API.


πŸ—‚οΈ Project Structure

Here’s how the project is organized:

jisho_microservice/
β”œβ”€β”€ app.py                 # Main Python application
β”œβ”€β”€ requirements.txt       # Dependencies (Flask, requests)
β”œβ”€β”€ templates/             # HTML templates
β”‚   β”œβ”€β”€ index.html         # Form page
β”‚   └── result.html        # Results page
β”œβ”€β”€ static/
β”‚   └── style.css          # Simple styling for the pages

πŸ” How It Works – Request Flow

  1. User visits / β†’ Sees a simple form to input a Japanese word.
  2. Form submits to /search β†’ The backend takes the word, sends a request to https://jisho.org/api/v1/search/words?keyword={word}.
  3. Jisho API responds β†’ We parse the JSON and display the result nicely on the webpage.

It’s a self-contained, classic example of:

  • Frontend input
  • Backend logic
  • External API integration
  • Displaying parsed results in the UI

πŸ”‘ Key Logic (Code Snippet)

Here’s the core Flask logic in app.py:

from flask import Flask, render_template, request
import requests

app = Flask(__name__)

JISHO_API = "https://jisho.org/api/v1/search/words?keyword="

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/search', methods=['POST'])
def search():
    word = request.form['word']
    response = requests.get(JISHO_API + word)
    data = response.json()
    results = data['data'] if data['data'] else []
    return render_template('result.html', word=word, results=results)

if __name__ == '__main__':
    app.run(debug=True)

This short snippet demonstrates how to:

  • Define routes using Flask
  • Handle form input
  • Call an external API using requests
  • Pass API data into HTML templates for rendering

πŸ”— GitHub Repository

You can find the full working code here:
πŸ‘‰ https://www.github.com/jansenzjh/jisho_service

Feel free to clone, fork, or contribute!


πŸ›£οΈ Future Roadmap

This is just the beginning. Here’s what I plan to add:

πŸš€ 1. More APIs for Japanese Learners

  • Kana to Kanji converter
  • Furigana generator
  • Grammar explanations

πŸ”§ 2. GitHub Actions

  • CI/CD pipeline to lint, test, and deploy automatically

🏑 3. Self-Hosted Server

  • Build a deployment pipeline to a VPS or home lab
  • Use Docker to containerize the microservice

🌐 4. JSON API Version

  • Add /api/search?word=猫 endpoint to return JSON instead of HTML

πŸ’¬ Final Thoughts

This project is a simple but real example of a microservice that talks to an external API, processes the response, and renders a clean UI β€” all in under 100 lines of code. If you’re learning Python, Flask, or just want to see how microservices work at a small scale, this is a great place to start.

Back to Blog