Computing facilities are an essential part of the fabric of our society, and an ever-increasing number of computing devices is deployed within the environment in which we live. The vision of pervasive computing is becoming real. However, to effectively exploit the opportunities offered by pervasiveness, we need to meet new requirements: (i) pervasive applications should be able to dynamically configure themselves, also benefiting from third-party functionalities discovered at run time and, (ii) pervasive applications should be aware of, and resilient to, environmental changes. To this end, the PRIME middleware leverages on REST principles to facilitate both the development and the run-time adaptation of pervasive applications. Furthermore, to deal with the high degree of dynamics inherent to pervasive environments, PRIME promotes the exploitation of Emergent Semantics as enabling technique for achieving resource discovery.