The pervasive computing vision of the future communication and computational infrastructure is that we will be everywhere virtually connected with invisible computers, embedded in the environment. In this context, the challenge is to provide a middleware support that allows applications to have minimal assumptions about the environment while being able to dynamically adapt to the surrounding context. Specifically, the middleware should (i) deal with the run-time growth of the application in terms of involved resources (flexibility), (ii) accommodate heterogeneous and unforeseen functionalities into the running application (genericity), and (iii) discover new functionality at run time and rearrange the application accordingly (dynamism). To this extent, we devised the P-REST (Pervasive REST) architectural style and built the P RIME (P-rest Runtime) middleware to support it. PRIME allows a quick and effective development and execution P-REST applications by leveraging functional programming and code mobility.