🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# Athena / web service yazımı rest ile

 

1-) C# Athena -  web service yazımı rest ile

1-) web service yazımı rest ile (Visual Studio 2015)

new project -> Web ->ASP.Net Web Application -> Empty -> Web Api -> Next

2-) Controller -> sağtık -> new controller -> Add controller -> Web api 2 read/write -> next

3-) personController.cs

using System.Collections.Generic;

using System.Web.Http;

using RestWebService.Models;

 

namespace RestWebService.Controllers {

    public class personController : ApiController {

        // GET: api/person

        public IEnumerable<string> Get() {

            return new string[] { "value1", "value2" };

        }

        // GET: api/person/5

        public Person Get(int id) {

            Person person = new Person();

            person.id=1;

            person.ad="Ramazan";

            person.soyad="HABER";

            return person;

        }

        // POST: api/person

        public void Post([FromBody]Person value) {

           Person yeni = new Person();

            yeni.ad= value.ad;

            

        }

        // PUT: api/person/5

        public void Put(int id, [FromBody]string value) {

        }

        // DELETE: api/person/5

        public void Delete(int id) {

        }

    }

}

4-) Models -> sağtık -> new class -> Person.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

namespace RestWebService.Models {

    public class Person {

        public int id { get;set;}

        public string ad { get;set;}

        public string soyad { get; set; }

    }

}

5-) Postman kur dene

get için -> http://localhost:60308/api/person/5

 post için -> http://localhost:60308/api/person

postman -> Body -> raw-> JSON(aplication/json) ->

{

    "id": 1,

    "ad": "Ramazan",

    "soyad": "HABER"

}

 2021 Ocak 18 Pazartesi
 433