I have a class with @restresource. To which a request is coming to insert the record. How can we identify what kind of request is coming in. Is it XML or JSON format. Is there any way to identify incoming request. Please help me if is possible.
Unless you are working with the raw content, any parameters that your REST method has Salesforce will automatically attempt to de-serialize from the request body, so you wouldn't need to know the content type in that scenario.
If you do want to work with the raw content, then to determine the type you'd need to inspect the request object:
RestRequest req = RestContext.request; String contentType = req.headers.get('Content-Type');
Not sure about the method but type of request, JOSN or XML, should be predefined in data contract itself.