Evaluating $\int\limits_0^\infty \frac{e^x}{1+e^{2x}}\mathrm dx$, alternate methods

If you want to avoid the limit to infinity, you can use the change of variable $e^x=1/u$ instead, and get$$\int_0^\infty\frac{e^x}{1+e^{2x}}dx=\int_1^0\frac{-\frac{du}{u^2}}{1+\frac1{u^2}}=-\int_1^0\frac{du}{1+u^2}=-\arctan(u)\Big|_1^0=\frac\pi4.$$


If you know complex analysis, you can use the residue theorem. Consider

$$ \oint_C \frac{dz}{\cos{z}} $$

where $C$ is a rectangle with vertices in the complex plane $-i R$, $\pi-i R$, $\pi+i R$,$i R$. The contour integral is then

$$\int_0^{\pi} \frac{dx}{\cos{(x-i R)}} + i \int_{-R}^R \frac{dy}{\cos{(\pi+i y)}} + \int_{\pi}^0 \frac{dx}{\cos{(x+i R)}}+ i \int_{R}^{-R} \frac{dy}{\cos{(i y)}}$$

Now, the integrals over $x$ vanish because they combine to form

$$- i 2 \int_0^{\pi} dx \frac{\sinh{R} \sin{x}}{\sinh^2{R}+\cos^2{x}} = - i 2 \arctan{\left ( \frac1{\sinh{R}}\right )} $$

which clearly vanishes as $R \to \infty$. Thus, in this limit, the contour integral is equal to

$$i \int_{-\infty}^{\infty} dy \left ( \frac1{\cos{(\pi+i y)}} - \frac1{\cos{(i y)}} \right ) = -i 2 \int_{-\infty}^{\infty} \frac{dy}{\cosh{y}}$$

By the residue theorem, the contour integral is also equal to $i 2 \pi$ times the residue of $1/\cos{z}$ at the pole $z=\pi/2$ (the only pole within $C$), which is $1/(-\sin{(\pi/2)}) = -1$. Thus,

$$ -i 2 \int_{-\infty}^{\infty} \frac{dy}{\cosh{y}} = i 2 \pi (-1) $$

and using the exponential definition of cosh, we get that

$$\int_0^{\infty} dy \frac{e^y}{1+e^{2 y}} = \frac{\pi}{4} $$