<commit_before>const requestHeaders = new Headers({ 'Authorization': 'i-said-so' })

export function getAllCategories() {
  const url = `http://localhost:3001/categories`
  const requestInit = { method: 'GET', headers: requestHeaders }
  console.log('fetching all categories from url', url);

  return fetch(url, requestInit)
    .then(res => res.json())
}

export function getPosts(category) {
  const url = category === '' ?
    `http://localhost:3001/posts` :
    `http://localhost:3001/${category}/posts`
  const requestInit = { method: 'GET', headers: requestHeaders }
  console.log('fetching all posts from url', url);
  
  return fetch(url, requestInit)
    .then(res => res.json())
}

export function getSpecificEntry(id, type) {
  const url = type === 'comment' ?
    `http://localhost:3001/comments/${id}`:
    `http://localhost:3001/posts/${id}`
  const requestInit = { method: 'GET', headers: requestHeaders }
  console.log(`fetching ${type} ${id} from url`, url);
  
  return fetch(url, requestInit)
  .then(res => res.json())
}

export function getPostComments(postId) {
  const url = `http://localhost:3001/posts/${postId}/comments`
  const requestInit = { method: 'GET', headers: requestHeaders }
  console.log(`fetching post ${postId} comments from url`, url);
  
  return fetch(url, requestInit)
  .then(res => res.json())
}

export function vote(id, voteDirection, voteType) {
  const url = voteType === 'comment' ?
    `http://localhost:3001/comments/${id}`:
    `http://localhost:3001/posts/${id}`
  const requestInit = {
    method: 'POST',
    headers: requestHeaders,
    body: voteDirection
  }
  console.log(`posting a ${voteDirection} for ${id} to url`, url);
  
  return fetch(url, requestInit)
  .then(res => res.json())
}

export function addNewEntry(newEntry, type) {
  const url = type === 'comment' ?
    `http://localhost:3001/comments` :
    `http://localhost:3001/posts`
  const requestInit = {
    method: 'POST',
    headers: requestHeaders,
    body: JSON.stringify(newEntry)
  }
  console.log(`posting a new ${type} to url`, url);
  console.log(requestInit.body)
  <commit_msg>Content-Type for new entries<commit_after>const requestHeaders = new Headers({ 'Authorization': 'i-said-so' })

export function getAllCategories() {
  const url = `http://localhost:3001/categories`
  const requestInit = { method: 'GET', headers: requestHeaders }
  console.log('fetching all categories from url', url);

  return fetch(url, requestInit)
    .then(res => res.json())
}

export function getPosts(category) {
  const url = category === '' ?
    `http://localhost:3001/posts` :
    `http://localhost:3001/${category}/posts`
  const requestInit = { method: 'GET', headers: requestHeaders }
  console.log('fetching all posts from url', url);
  
  return fetch(url, requestInit)
    .then(res => res.json())
}

export function getSpecificEntry(id, type) {
  const url = type === 'comment' ?
    `http://localhost:3001/comments/${id}`:
    `http://localhost:3001/posts/${id}`
  const requestInit = { method: 'GET', headers: requestHeaders }
  console.log(`fetching ${type} ${id} from url`, url);
  
  return fetch(url, requestInit)
  .then(res => res.json())
}

export function getPostComments(postId) {
  const url = `http://localhost:3001/posts/${postId}/comments`
  const requestInit = { method: 'GET', headers: requestHeaders }
  console.log(`fetching post ${postId} comments from url`, url);
  
  return fetch(url, requestInit)
  .then(res => res.json())
}

export function vote(id, voteDirection, voteType) {
  const url = voteType === 'comment' ?
    `http://localhost:3001/comments/${id}`:
    `http://localhost:3001/posts/${id}`
  const requestInit = {
    method: 'POST',
    headers: requestHeaders,
    body: voteDirection
  }
  console.log(`posting a ${voteDirection} for ${id} to url`, url);
  
  return fetch(url, requestInit)
  .then(res => res.json())
}

export function addNewEntry(newEntry, type) {
  const newEntryHeader = new Headers(requestHeaders)
  newEntryHeader.append('Content-Type', 'application/json')
  
  const url = type === 'comment' ?
    `http://localhost:3001/comments` :
    `http://localhost:3001/posts`
  const requestInit = {
    method: 'POST',
    headers: newEntryHeader,
    body: JSON.stringify(newEntry)
  }
  console.log(`posting a new ${type} to url`, url);
  
{'fraction_non_alphanumeric': 0.16155088852988692, 'fraction_numerical': 0.018462958689129932, 'mean_word_length': 4.09283196239718, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '777757', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1376, 'n_words': 334}