<commit_before>## Parse a document by automatically detecting its MIME type.

Use this API to send a file or to parse a file located on the server: OpenSearchServer will try to automatically detect its MIME type to apply the correct parser on it.

**Requirement:** OpenSearchServer v1.5.11

### Call parameters

**URL:** ```/services/rest/parser?name={optionnal_file_name}&type={optionnal_mime_type}&path={file_to_crawl_if_located_on_server}&p.{any_parser_property}={property_value}```

**Method:** ```PUT```

**Header**:

- _**Content-Type**_ (required): ```application/json```
- _**Accept**_ (optional returned type): ```application/json``` or ```application/xml```

**URL parameters:**

- **_lang_** (optionnal): The language of the document.
- **_p.{any_parser_property}_** (optionnal): Any property of the parser.
- **_type_** (optionnal): MIME type of the file, if known. This will help OpenSearchServer detecting the correct parser.

**If parsing a file located on the server:** 

- **_path_**: File path for file to parse if it is located on the server.

**If sending a file to parse:**

- **_name_** (optionnal): The name of the file that is sent. This will help OpenSearchServer detecting the correct parser.

**Binary data (PUT):**

If the file is sent to the server for parsing: body of the request is the file to parse.

### Success response

OpenSearchServer will try to detect which parser to use on the file. It will use:

1. name of the file, if given as a parameter, and especially its extension.
2. type of the file, if given as a parameter.
3. header of the file.

It is a good practice to send at least the name of the file to ensure correct detection of the parser to use.

The parser has been applied to file (sent or the one whose path has been given as parameter). Appropriate parser has been automatically detected and used. Every extracted fields are returned.

**HTTP code:**
200

**Content (application/json):**


    {  
    "items":[  
      [  
         {  
            "fieldName":"author",
            "values":[  
               "m.garden"
            ]
         },
         {  
            "fieldName":"content",
            "values":[  
               "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
			   "Vivamus facilisis enim in libero rhoncus, id pretium augue porta.",
			   "Cras nec ante risus. Aenean condimentum, velit non"
			   "blandit egestas, leo felis pharetra sapien, sed feugiat."
            ]
         },
         {  
            "fieldName":"creation_date",
            "values":[  
               "Tue Feb 10 11:43:28 CET 2013"
            ]
         },
         {  
            "fieldName":"lang",
            "values":[  
               "fr"
            ]
         },
         {  
            "fieldName":"lang_method",
            "values":[  
               "ngram recognition"
            ]
         },
         {  
            "fieldName":"modification_date",
            "values":[  
               "Tue Feb 12 11:43:28 CET 2013"
            ]
         },
         {  
            "fieldName":"number_of_pages",
            "values":[  
               "2"
            ]
         },
         {  
            "fieldName":"producer",
            "values":[  
               "GPL Ghostscript 8.64"
            ]
         },
         {  
            "fieldName":"title",
            "values":[  
               "Rules of competition"
            ]
         }
      ]
     ]
    }        

### Error response

The parsing failed. The reason is provided in the content.

**HTTP code:**
500

### Sample call

**Using CURL:**
<commit_msg>Update parse_detect_mime.md<commit_after>## Parse a document by automatically detecting its MIME type.

When this API is used to send a file (or to parse a file on the server), OpenSearchServer attempts to detect the file's MIME type to apply the correct parser.

**Requirement:** OpenSearchServer v1.5.11

### Call parameters

**URL:** ```/services/rest/parser?name={optionnal_file_name}&type={optionnal_mime_type}&path={file_to_crawl_if_located_on_server}&p.{any_parser_property}={property_value}```

**Method:** ```PUT```

**Header**:

- _**Content-Type**_ (required): ```application/json```
- _**Accept**_ (optional returned type): ```application/json``` or ```application/xml```

**URL parameters:**

- **_lang_** (optionnal): The language of the document.
- **_p.{any_parser_property}_** (optionnal): Any property of the parser.
- **_type_** (optionnal): MIME type of the file, if known. This will help OpenSearchServer detect the correct parser.

**If parsing a file located on the server:** 

- **_path_**: File path to the file on the server.

**If sending a file to parse:**

- **_name_** (optional): The name of the file to send. This will help OpenSearchServer detect the correct parser.

**Binary data (PUT):**

If the file is sent to the server for parsing, the body of the request is the file to parse.

### Success response

OpenSearchServer will try to detect which parser to use on the file. The clues used to do so are:

1. the name of the file, if given as a parameter, and in particular its extension.
2. the type of the file, if given as a parameter.
3. the file's header.

We strongly suggest sending at least the name of the file to increase the odds of a correct detection.

If the process suceeds, the appropriate parser gets applied to the designated file. Every extracted field then gets returned.

**HTTP code:**
200

**Content (application/json):**


    {  
    "items":[  
      [  
         {  
            "fieldName":"author",
            "values":[  
               "m.garden"
            ]
         },
         {  
            "fieldName":"content",
            "values":[  
               "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
			   "Vivamus facilisis enim in libero rhoncus, id pretium augue porta.",
			   "Cras nec ante risus. Aenean condimentum, velit non"
			   "blandit egestas, leo felis pharetra sapien, sed feugiat."
            ]
         },
         {  
            "fieldName":"creation_date",
            "values":[  
               "Tue Feb 10 11:43:28 CET 2013"
            ]
         },
         {  
            "fieldName":"lang",
            "values":[  
               "fr"
            ]
         },
         {  
            "fieldName":"lang_method",
            "values":[  
               "ngram recognition"
            ]
         },
         {  
            "fieldName":"modification_date",
            "values":[  
               "Tue Feb 12 11:43:28 CET 2013"
            ]
         },
         {  
            "fieldName":"number_of_pages",
            "values":[  
               "2"
            ]
         },
         {  
            "fieldName":"producer",
            "values":[  
               "GPL Ghostscript 8.64"
            ]
         },
         {  
            "fieldName":"title",
            "values":[  
               "Rules of competition"
            ]
         }
      ]
     ]
    }        

### Error response

The parsing failed. The reason why is provided in the content.

**HTTP code:**
500

### Sample call

**Using CURL:**

{'fraction_non_alphanumeric': 0.11352183650615902, 'fraction_numerical': 0.011478163493840985, 'mean_word_length': 1.9895397489539748, 'pattern_counts': {'":': 38, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3832998', 'n_tokens_mistral': 2105, 'n_tokens_neox': 1968, 'n_words': 711}