Hello! I do it for definition because Gauss's law not possible.
I use cartesian coordinates:
$$dq=\lambda dx'\text{because is only in x direction}$$
$$\vec{r'}=(x',0)$$
$$\vec{r}-\vec{r'}=(x-x',y)$$
$$\hat{r}=\frac{(x-x',y)}{\sqrt{(x-x')^{2}+y^{2}}}$$...