How do you win with the King's Indian Defense?
You prepare for ...e5.
If your opponent exchanges, you fight for the open file.
If your opponent pushes forward, you prepare for a ...f5 pawn break, gain space on the kingside and coordinate your pieces to go after the opponent's king. Meanwhile, you have to slow down White's queenside attack with moves like ...c5.
If your opponent ignores the break, play ...Nc6 to try and force him to push his pawn forward.

Theory - the KID is all about theory really. Both sides attacking each other - whoever causes the most damage wins in the end. The KID is very heavily theoretical. Of course, there are other KID variations, but I'm talking the classical lines.
Judging by the one rapid game you've played on this site, you shouldn't use it.

I tried it out in my earlier days of playing chess and got crushed then didn't try it again. With daily chess and explorer it is easier now to ensure you at least can look at the correct opening lines as long as your opponent also follows them, and of course if you look at grandmaster games you can see what their strategies were.

It appears strange that with KID u were on defensive for a lot of time.I play it because with that defence black can only attack.

There are half a dozen distinct plans associated with that opening.
The ... e5 plan is one of them, of course, or the ... c5 plan, or (under certain circumstances) ... Nc6 or even ... c6 and ... b5.
I could post a few KID games that I've played, if you like. I'm not a very good player, but I've had some experience with the opening both online and in OTB tournaments.

There are half a dozen distinct plans associated with that opening.
The ... e5 plan is one of them, of course, or the ... c5 plan, or (under certain circumstances) ... Nc6 or even ... c6 and ... b5.
I could post a few KID games that I've played, if you like. I'm not a very good player, but I've had some experience with the opening both online and in OTB tournaments.
I would love to see a game

There are half a dozen distinct plans associated with that opening.
The ... e5 plan is one of them, of course, or the ... c5 plan, or (under certain circumstances) ... Nc6 or even ... c6 and ... b5.
I could post a few KID games that I've played, if you like. I'm not a very good player, but I've had some experience with the opening both online and in OTB tournaments.
I would love to see a game
Here is a recent one. It was a rapid game on here, not a slow over the board game, so the quality is a little on the low end, but it is a Classical Kings Indian.
https://www.chess.com/live/game/4658575267
I have played with the KID before and I was on the defensive for most of match and then I went all out offensive at the end. I ended up winning of course, but I would like to know what is the most effective way to use the King's Indian Defense?