DEV Community

Cover image for Hindi Jokes API : GET random hindi jokes
Jon Snow
Jon Snow

Posted on • Updated on

Hindi Jokes API : GET random hindi jokes

Free forever

I created a REST API using node Js, express, and MongoDB. It uses the Hindi Jokes API to fetch random jokes in the Hindi language. The app is deployed on Render.

API Link

  https://hindi-jokes-api.onrender.com
Enter fullscreen mode Exit fullscreen mode

Custom Endpoints

Random joke

Endpoint: /jokes

Example: https://hindi-jokes-api.onrender.com/jokes?api_key=YourApiKey

Response:

{
    "_id": "631c381d798f9e2887b4cba1",
    "status": "Success",
    "jokeContent": "आओ 2 Min मौन रखे उन लड़कियों के लिए.. जिनकी शक्ल Nokia 1100 जैसी है और घमंड Iphone14 जैसा…. 😆🤣😋😉",
    "jokeNo": 116,
    "created_by": "Amit Sharma"
}
Enter fullscreen mode Exit fullscreen mode

Specify count (MAX 50)

In order to get multiple jokes in a single request specify the count with the following endpoint.

Endpoint: /jokes/{count}

Example: https://hindi-jokes-api.onrender.com/jokes/2?api_key=YourApiKey

Response:

{
"status": "Success",
"created_by": "Amit Sharma",
"totalJokes": "2",
"data": [
   {
      "_id": "63199fb5f02231a5ee2965a5",
      "jokeContent": "शादी के दो दिन बाद दूल्हा उस ब्यूटी पार्लर में गया जहां से उसकी बीवी ने शादी के लिए मेकअप करवाया था उसने पार्लर वाली मैडम को आईफोन 7 गिफ्ट किया और थैंक्यू बोलकर चला                         आया मैडम ने खुशी खुशी आईफोन का डब्बा खोला तो उसमें नोकिया 1100 पड़ा था साथ में एक पर्ची भी थी जिस पर लिखा था मुझे भी ऐसा ही महसूस हुआ था😆🤣😋😉 ",
       "jokeNo": 71
   },
  {
       "_id": "63217239def3f928de48b025",
       "jokeContent": "थप्पड मारने पर नाराज वाईफ से हसबंड बोला:  ...आदमी उसी को मारता है जिससे वो प्यार करता है.   ..वाईफ ने हसबंड को 2 थप्पड मारे और बोली  ...आप क्या समझते है मै                          आपसे प्यार नही करती ... 😆🤣😋😉",
       "jokeNo": 141
   }
 ]
}
Enter fullscreen mode Exit fullscreen mode

GITHUB URL

for more updates check the GitHub repository of the API

https://github.com/amitSharma7741/Hindi_jokes_api
Enter fullscreen mode Exit fullscreen mode

How to use

You can use this API in your projects. Just make a GET request to the API endpoint and you will get a random joke in the Hindi language. You can also use the API in your browser by visiting the API endpoint.

Using Fetch

const fetchData = async () => {
    const url = "https://hindi-jokes-api.onrender.com/jokes?api_key=YourApiKey"
    const response = await fetch(url);
    const data = await response.json();
    console.log(data)
}
Enter fullscreen mode Exit fullscreen mode

Using Axios

// First you need to install Axios
npm I Axios

// use Axios 

const sendGetRequest = async () => {
    const URL = "https://hindi-jokes-api.onrender.com/jokes?api_key=YourApiKey"
    try {
        const resp = await Axios.get(URL);
        console.log(resp.data);
    } catch (err) {
        // Handle Error Here
        console.error(err);
    }
};

Enter fullscreen mode Exit fullscreen mode

If you are getting any issues with API feel free to make a comment or write your issue on github repo

Top comments (1)

Collapse
 
snowbearchair profile image
I AM CC

Error -

JSON parsing error: Unexpected token j in JSON at

position 192 Invalid JSON:

{"_id":"6319a43df02231a5ee2965e4","status":"Success"

"jokeContent":"इतिहास गवाह हैं कि टमाटर हो या प्याज जब जब

इनकी कीमतें बढ़ी हैं तब तब इनको खाने की दिल में तीव्र इच्छा जागृत

हुई हैं氟配頡,"jokeNo":92,"usage": [{"date":"2024-02-26","count":9}],"created_by":"Amit Sharma"}
Enter fullscreen mode Exit fullscreen mode

Code -

var result = JSON.parse(content);

var id = result._id;
var status = result.status;
var jokeContent = result.jokeContent;
var jokeNo = result.jokeNo;
var created_by = result.created_by;

Bot.sendMessage("Id: " + id + "\nstatus: " + status + "\njokeContent: " + jokeContent + "\njokeNo: " + jokeNo + "\ncreated_by: " + created_by);
Enter fullscreen mode Exit fullscreen mode

Please fix this code and give me the corrected code 🥺

I can reward you with 10 BB Point or this bot - @MegaHelperOBot