Yes, one can use a periodic extension of a function in order to express it as a Fourier series. A typical exercise on the subject is: consider the function $f(x)=x^2$ on the interval $[0,L]$, extended periodically... This means you'll have an expansion in terms of $\cos\frac{2\pi}{L}n x$ and $\sin\frac{2\pi}{L} nx$ (as these are periodic with period $L$), and the coefficients are
$$
A_n = \frac{2}{L}\int_0^L f(x)\cos \frac{2\pi n}{L} x\,dx, \quad
B_n = \frac{2}{L}\int_0^L f(x)\sin \frac{2\pi n}{L} x\,dx
$$
for $n=0,1,2,\dots$ (by convention, the series contains $A_0/2$ as the constant term, which allows the above formula to work also when $n=0$.) The interval need not be symmetric ($[-a,a]$) in order for the Fourier series to exist; however, it's often more convenient to integrate over symmetric intervals.
The quality of approximation near the endpoints may be poor if the behavior of the function at both ends does not match. To mitigate this issue, and also to avoid the problem of non-symmetric interval, I suggest using even periodic extension: that is, first extend the function to $[-L,L]$ as an even function, $f(-x)=f(x)$, and then extend periodically as a function with period $2L$, meaning $f(x+2L)=f(x)$. An advantage of doing so is that $f(-L)=f(L)$ automatically, so the values at the end of the interval $[-L,L]$ match.
In practice, the above means using the cosine Fourier series
$$
f(x) = \frac{A_0}{2} + \sum_{n=1}^\infty A_n\cos \frac{\pi n}{L} x
$$
where
$$
A_n = \frac{2}{L}\int_0^L f(x)\cos \frac{\pi n}{L} x\,dx, \quad n=0,1,2,\dots
$$
My blog post illustrates the advantage of using cosines in such situations on the example of non-periodic function $e^x$.
Best Answer
If f(x) is periodic with period $2\pi$ and f’(x) exists and is finite for $-\pi<x<\pi$ then f can be written as a Fourier series:
$$f(x)=\sum_{n=-\infty}^{\infty}a_{n}e^{inx}$$
where
$$a_{n}=\frac{1}{2\pi}\int_{-\pi}^{\pi}f(t)e^{-int}dt$$.
We shall also use the fact that
$$\int_{-\pi}^{\pi}e^{-int}dt=0$$
and
$$e^{-in\pi}=(e^{-i\pi})^{n}=(-1)^{n}=(e^{i\pi})^{n}=e^{in\pi}$$ Now let f(x) be periodic with period $2\pi$ where f(x) = x for $-\pi<x<\pi$ and f(-π)=f(π)=0. Let us calculate $a_{n}$ for n≠0. The easiest way is to use partial integration:
$$a_{n}=\frac{1}{2\pi}\int_{-\pi}^{\pi}te^{-int}dt =\frac{(-1)^{n}}{2\pi in}(\pi-(-\pi))-\frac{(-1)^{n}}{2\pi in}\int_{-\pi}^{\pi}e^{-int}dt=\frac{(-1)^{n}}{in}-0$$
For n=0 we have
$$a_{0}=\frac{1}{2\pi}\int_{-\pi}^{\pi}tdt =\frac{1}{2\pi}\frac{1}{2}(\pi^{2}-(-\pi)^{2})=0$$ Since f(x) is differentiable at π/2, the Fourier series converges at that point, giving $$\frac{\pi}{2}=\sum_{n=-\infty}^{-1}\frac{(-1)^{n}}{in}e^{in\frac{\pi}{2}}+0+\sum_{n=1}^{\infty}\frac{(-1)^{n}}{in}e^{in\frac{\pi}{2}}$$ Changing n to –n in the first sum, we get $$\frac{\pi}{2}=\sum_{n=1}^{\infty}\frac{(-1)^{n}}{-in}e^{-in\frac{\pi}{2}}+\sum_{n=1}^{\infty}\frac{(-1)^{n}}{in}e^{in\frac{\pi}{2}}$$ Now $\frac{e^{inx}-e^{-inx}}{2i}=\sin(nx)$ and therefore $$\frac{\pi}{2}=2\sum_{n=1}^{\infty}\frac{(-1)^{n}}{n}\sin(\frac{n\pi}{2}).$$ Since $\sin(\frac{n\pi}{2})$ is 0 for all even multiples of $\pi/2$ and alternates between +1 and -1 for odd multiples, we have $$\frac{\pi}{4}=\sum_{n=1}^{\infty}\frac{(-1)^{n-1}}{2n-1}$$