We talked about two integrals, one is $$ \int_{\theta=0}^{2\pi} \frac{1}{1 + \epsilon \cos(\theta)} d\theta, 0 < \epsilon \ll 1 $$ the other is $$ \int_{x=0}^\infty \frac{1}{1+x^n} dx $$
Suppose we have a ration function involving $\sin(\theta)$ and $\cos(\theta)$, $R(\sin \theta, \cos \theta)$, and we consider integral of the form $$ \int_{\theta=0}^{2\pi} R(\sin \theta, \cos \theta) d \theta$$ Then, we can replaced $e^{i\theta} = z$, let $z$ run on the unit circle.
Then we will get a rational function of $z$ as integrand, and the contour is the unit circle.
In our example, we get $$ I = \oint_{|z|=1} \frac{1}{1 + \epsilon (z+1/z)/2} dz/(iz) = (2/i) \oint_{|z|=1} \frac{1}{2z + \epsilon(z^2+1)} dz $$ We found the integrand function has two poles at $$ z_\pm = \frac{-2 \pm \sqrt{4 - 4\epsilon^2}}{2\epsilon} = \frac{-1 \pm \sqrt{1 - \epsilon^2}}{\epsilon} $$ We can check $z_+$ is within the unit circle, $z_-$ is outside it. Hence to apply residue theorem, we get $$ I = (2\pi i) (2/i) Res_{z=z_+} \frac{1}{2z + \epsilon(z^2+1)} = \frac{4\pi}{2 + 2 \epsilon z_+} = \frac{2\pi}{\sqrt{1-\epsilon^2}}$$
Consider $$\int_0^\infty \frac{1}{1+x^3} dx $$ We first truncate it to $$I_{1,R} = \int_0^R \frac{1}{1+x^3} dx $$ then $I_1 = \lim_{R \to \infty} I_{1,R}$ is what we want.
We next complete the integration contour to a full closed loop, by adding two more pieces of integral
We also know that $$ I_R = I_{1,R} + I_{2,R} + I_{3,R} = 2\pi i Res_{z = e^{\pi i / 3}} \frac{1}{z^3} = 2\pi i \frac{1}{3 e^{2\pi i / 3} } $$ taking limit $R \to \infty$, we can show (here I ignore it) that $I_{3,R} \to 0$, then $$ I_1 (1 - e^{i2\pi/3}) = 2\pi i \frac{1}{3 e^{2\pi i / 3} } $$ hence $$ I_1 = \frac{2\pi i}{3(e^{2\pi i/3} - e^{4\pi i/3} )}$$