Giter VIP home page Giter VIP logo

go-api-simple's Introduction

go-api-simple

A simple Go API implementation that searches on Wikipedia

About the API

Now, let's explain the code:

We define a WikipediaPage struct to represent the data we want to extract from the Wikipedia API response, including Title, Description, and Extract fields. In the main function, we create a new Gin router and define a route "/search/:query" to search for a Wikipedia page based on the provided query. The searchWikipedia function handles the API endpoint. It extracts the query parameter, calls the getWikipediaPage function to fetch data from the Wikipedia API, and returns the result as a JSON response. The getWikipediaPage function takes a query, constructs the Wikipedia API URL with the given query, and makes an HTTP GET request to the Wikipedia API. If the API request is successful (HTTP status code 200), it parses the JSON response into a WikipediaPage struct and returns it.

Getting Started

To run the API, open a terminal in the same directory as the main.go file and execute the following command:

go run main.go

The server will start, and you can access the API endpoint using tools like curl, Postman, or web browsers. For example:

To search for a Wikipedia page about "Golang": GET http://localhost:8080/search/Golang

The API will return information about the Wikipedia page, including the page title, description, and extract. Note that the example above is a basic demonstration of making API requests to Wikipedia. In a real-world scenario, you may want to add more error handling, caching, or rate limiting to improve the API's reliability and performance.

go-api-simple's People

Contributors

weber-stephen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.