Coder Social home page Coder Social logo

jayesh-agrawat / serverless-blog-api Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 45 KB

A simple serverless blog API using Google Cloud Functions, MongoDB, and Node.js. This project will allow you to create, read, update, and delete blog posts through API endpoints, showcasing your backend and serverless architecture skills.

JavaScript 100.00%

serverless-blog-api's Introduction

Serverless Blog API Documentation

Welcome to the documentation for the Serverless Blog API. This API allows you to create, read, update, and delete blog posts through various endpoints, showcasing the functionality of backend development using Google Cloud Functions, MongoDB, and Node.js.

Table of Contents

Introduction

The Serverless Blog API is a demonstration project that showcases how to build a simple backend using Google Cloud Functions, MongoDB, and Node.js. The API provides endpoints for performing CRUD (Create, Read, Update, Delete) operations on blog posts. It aims to demonstrate the principles of RESTful API design while leveraging serverless architecture.

Getting Started

To use the Serverless Blog API, you'll need the following:

  • A Google Cloud Platform account
  • A MongoDB instance or cluster
  • Node.js and npm installed on your local machine

Follow these steps to set up and run the API:

  1. Clone the project repository:
git clone https://github.com/jay-agrawat/serverless-blog-api
cd serverless-blog-api

Note : Currently Above Repository is Private

  1. Install the project dependencies:
npm install
  1. Configure environment variables: Create a .env file in the root directory and define the following variables:
MONGODB_URI=your-mongodb-uri
  1. Deploy the Cloud Functions: Deploy the Cloud Functions using the Google Cloud SDK or other deployment methods.
gcloud functions deploy blog_api_v1 --gen2 --runtime=nodejs20 --region=us-central1 --source=. --entry-point=app --trigger-http --allow-unauthenticated --memory 512Mi --max-instances=1

Endpoints

Base URL: https://us-central1-abiding-sunset-390217.cloudfunctions.net/blog_api_v1

Create a New Blog Post

  • Method: POST

  • Endpoint: /posts

  • Request Body:

{
  "title": "Sample Title",
  "content": "Sample Content",
  "author": "John Doe"
}
  • Response: 201 Created with the newly created post ID.

Get All Blog Posts

  • Method: GET
  • Endpoint: /posts
  • Response: 200 OK with an array of blog post objects.

Get a Single Blog Post by ID

  • Method: GET
  • Endpoint: /posts/{postId}
  • Response: 200 OK with the blog post object or 404 Not Found if the post doesn't exist.

Update a Blog Post

  • Method: PUT

  • Endpoint: /posts/{postId}

  • Request Body:

{
  "title": "Updated Title",
  "content": "Updated Content"
}
  • Response: 200 OK with a success message.

Delete a Blog Post

  • Method: DELETE
  • Endpoint: /posts/{postId}
  • Response: 200 OK with a success message.

Error Handling

The API provides meaningful error responses for various scenarios, including missing or invalid input data, resource not found, and internal server errors. The appropriate HTTP status codes are used to indicate the outcome of each request.

Deployment

Deploying the Cloud Functions can be done using the Google Cloud SDK or other deployment methods. Make sure to configure the necessary environment variables for connecting to your MongoDB instance.

gcloud functions deploy hello-node-function \
  --gen2 \      
  --runtime=nodejs20 \
  --region=us-central1 \
  --source=. \
  --entry-point=helloGET \
  --trigger-http \
 y--memory 512Mi --max-instances=1

Conclusion

The Serverless Blog API is a practical example of building a backend using Google Cloud Functions, MongoDB, and Node.js. It demonstrates how to implement CRUD operations and follows RESTful API design principles. Feel free to use this project as a foundation for learning and building more advanced applications.

serverless-blog-api's People

Contributors

jayesh-agrawat avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.